Mac dates ==> UNIX dates
Mac dates ==> UNIX dates
- Subject: Mac dates ==> UNIX dates
- From: Marc Myers <email@hidden>
- Date: Fri, 20 Oct 2006 13:28:10 -0600
Is there a simple way to convert a Mac date into an integer that can be
used as the -r parameter in the UNIX "date" command?
Currently, I'm using "date" in a shell script to generate a date/time
string representing the UNIX Epoch. I coerce that into a Mac date.
Then I subtract the Epoch date from the desired date/time, giving me a
result in seconds in scientific notation. I use a text routine to
convert the scientific notation to an integer (as text). That integer
can be plugged into the "date" command's -r parameter.
on formDate(theDate)
--get time 0 for the Unix side
set theEpoch to date (do shell script "date -r 0 +\"%a %b %e %Y
%H:%M:%S\"")
--current time in seconds from time 0, as text (for next bit)
set theDiff to (theDate - theEpoch) as text
--convert the scientific notation to an "integer" string
if theDiff contains "E" then
set thePower to (last character of theDiff) + 1
set theDiff to (first character of theDiff & (characters 3 thru -4 of
theDiff as text))
repeat until (length of theDiff) = thePower
set theDiff to theDiff & "0"
end repeat
end if
--do the shell script
return (do shell script ("date -r " & theDiff & " +\"%D %T\""))
end formDate
Is there a simpler way to do a conversion? From the man page, it
sounds like curl_getdate(3) would do it, but it doesn't seem to be
installed. It sure would be nice if AppleScript had a "long integer"
class...
Marc [10/20/2006 01:27:38 PM]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden