• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting UNIX TIME STAMP to Mac Os X Date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting UNIX TIME STAMP to Mac Os X Date


  • Subject: Re: Converting UNIX TIME STAMP to Mac Os X Date
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 13 Mar 2011 13:10:36 +0100

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

  • Follow-Ups:
    • Re: Converting UNIX TIME STAMP to Mac Os X Date
      • From: Bernardo Hoehl <email@hidden>
References: 
 >Converting UNIX TIME STAMP to Mac Os X Date (From: Bernardo Hoehl <email@hidden>)

  • Prev by Date: Re: Converting UNIX TIME STAMP to Mac Os X Date
  • Next by Date: Can't get the change download folder in Safari script to work - ui scripting
  • Previous by thread: Re: Converting UNIX TIME STAMP to Mac Os X Date
  • Next by thread: Re: Converting UNIX TIME STAMP to Mac Os X Date
  • Index(es):
    • Date
    • Thread