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: Bernardo Hoehl <email@hidden>
- Date: Sun, 13 Mar 2011 14:36:15 -0300
Hello Axel, Nigel, Luther and Steve,
You have all been very helpfull.
I will give a try in all sugestions.
Thanks!
Bernardo
===========================
On 13.03.2011, at 9:10 AM, Axel Luttgens wrote:
> Le 12 mars 2011 à 19:19, Bernardo Hoehl a écrit :
>
>> Helo my friends,
>>
>>
>> I am trying to write a handler that will converter Unix Time Stamp to a Mac Os X formated date.
>>
>> It should be universal for most locales and work on 10.5 and 10.6, so this is why I am using Unix Time Stamp on my records in a Database.
>>
>>
>> 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.
>
> Hello Bernardo,
>
> You could have a look at:
>
> http://lists.apple.com/archives/applescript-users/2007/Nov/msg00511.html
>
> Other threads appeared later on the list as well, all with strange behaviors of dates in AppleScript on Leopard.
>
> The bug seems to have been corrected somewhere between 10.5.3 and 10.5.8: your script appears to behave correctly here with 10.5.8.
>
> If updating the OS isn't an option, but you may afford a slight speed decrease for convertUnixTimeStamp(), there's the quick and dirty workaround: proceed in chunks; for example:
>
> on convertUnixTimeStamp(UTS) -- For 10.5.x, with UTS > 0
> local D
> set D to current date
> set time of D to 0
> set day of D to 1
> set month of D to 1
> set year of D to 1970
> set UTS to UTS as number
> repeat while UTS > 500000000
> set D to D + 500000000
> set UTS to UTS - 500000000
> end repeat
> set D to D + UTS
> end convertUnixTimeStamp
>
> HTH,
> Axel
>
> _______________________________________________
> 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
>
_______________________________________________
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