Re: Converting UNIX TIME STAMP to Mac Os X Date
Re: Converting UNIX TIME STAMP to Mac Os X Date
- Subject: Re: Converting UNIX TIME STAMP to Mac Os X Date
- From: Nigel Garvey <email@hidden>
- Date: Sun, 13 Mar 2011 10:20:33 +0000
Bernado Hoehl wrote on Sat, 12 Mar 2011 15:19:21 -0300:
>This script works on 10.6, but will return a crasy date (back to 1974)
>on 10.5.3:
>
>--UTS = 1299244966 --> "Friday, March 4, 2011 1:22:46 PM"
>
>my convertUnixTimeStamp("1299244966")
>on convertUnixTimeStamp(UTS)
> set unixTimeStampStarts to current date -- just any date
> set time of unixTimeStampStarts to 0
> set day of unixTimeStampStarts to 1
> set month of unixTimeStampStarts to 1
> set year of unixTimeStampStarts to 1970
> return unixTimeStampStarts + (UTS as integer)
>end convertUnixTimeStamp
>
>
>I apreciate your comments on the problem.
On my 10.4.11 machine, the coercion to integer fails, presumably because
UTS is too big. I can get the desired result either by coercing to
number instead or by leaving out the explicit coercion altogether.
Hopefully, that will fix the problem in 10.5.3 too.
The date returned by your method is GMT, which may be what you want. If
you want the result in your computer's local time zone, you could do it
this way:
on timestampToLocalDate(timestampStr)
-- Get the local date as yyyymmddhhmmss as number
set isot to (do shell script ("/bin/date -r " & timestampStr & " +%Y
%m%d%H%M%S")) as number
set localDate to (current date)
set localDate's day to 1
set localDate's year to isot div 1.0E+10
set localDate's month to isot mod 1.0E+10 div 100000000
set localDate's day to isot mod 100000000 div 1000000
set localDate's time to isot mod 1000000 div 10000 * hours + isot
mod 10000 div 100 * minutes + isot mod 100
return localDate
end timestampToLocalDate
set UTS to "1299244966"
timestampToLocalDate(UTS)
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden