• 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: UNIX DATE
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UNIX DATE


  • Subject: Re: UNIX DATE
  • From: Nigel Garvey <email@hidden>
  • Date: Sun, 25 Apr 2004 16:08:40 +0100

John Mistler wrote on Sat, 24 Apr 2004 14:15:24 -0700:

>Is there a simple way to convert an applescript date such as:
>
>date Friday, December 24, 2004 3:00:00 PM
>
>to
>
>a UNIX format such as
>
>2004-12-24 15:00:00

on dateToAUnixFormat(theDate)
set {year:y, day:d, time:t} to theDate

copy theDate to b
set b's month to January
set m to (b - 2500000 - theDate) div -2500000

tell (y * 10000 + m * 100 + d) as string
set sDate to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7
thru 8
-- set sDate to it
end tell

tell (1000000 + t div hours * 10000 + t mod hours div minutes * 100 +
t mod minutes) as string
return sDate & space & text 2 thru 3 & ":" & text 4 thru 5 & ":" &
text 6 thru 7
-- return sDate & text 2 thru 7
end tell
end dateToAUnixFormat

dateToAUnixFormat(date "Friday, December 24, 2004 3:00:00 PM")
--> "2004-12-24 15:00:00"

>or
>
>20041224150000 ?

Uncomment the commented lines above and use each instead of the line
immediately preceding it. Alternatively, you could abbreviate the handler:

on dateToAUnixFormat(theDate)
set {year:y, day:d, time:t} to theDate
copy theDate to b
set b's month to January

return (y * 10000 + (b - 2500000 - theDate) div -2500000 * 100 + d as
string) & text 2 thru 7 of (1000000 + t div hours * 10000 + t mod hours
div minutes * 100 + t mod minutes as string)
end dateToAUnixFormat

dateToAUnixFormat(date "Friday, December 24, 2004 3:00:00 PM")
--> "20041224150000"


Paul Berkowitz wrote on Sat, 24 Apr 2004 16:33:22 -0700:

>set s to ((date "Friday, December 24, 2004 3:00:00 PM") - (date "Thursday,
>January 1, 1970 12:00:00 AM"))
>set s to my Stringify(s)
>do shell script "date -ur " & s & " \"+ %F %T\""
>--> "2004-12-24 15:00:00"

It gives " F 15:00:00" on my machine. Changing the last line as follows
seems to work, though:

do shell script "date -ur " & s & " \"+%Y-%m-%d %T\""

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: UNIX DATE
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: FolderActions bug?
  • Next by Date: Re: UNIX DATE
  • Previous by thread: Re: UNIX DATE
  • Next by thread: Re: UNIX DATE
  • Index(es):
    • Date
    • Thread