Re: parsing Unix date
Re: parsing Unix date
- Subject: Re: parsing Unix date
- From: Graff <email@hidden>
- Date: Sat, 10 Jan 2004 02:16:20 -0500
On Jan 9, 2004, at 3:13 PM, Paul Berkowitz wrote:
On 1/9/04 10:59 AM, "Graff" <email@hidden> wrote:
Well, the easiest way is to simply format the date string in a way
AppleScript can parse easily:
----------
set d to (do shell script "date '+%A, %B %e, %Y %T'")
---> "Friday, January 9, 2004 13:07:10"
date d
---> date "Friday, January 9, 2004 1:07:10 PM"
----------
That's not necessary. AppleScript is tremendously versatile about
understanding dates (almost too versatile). As long as you include all
the
info you need (day, month, year, hours, minutes, seconds as desired)
you can
omit weekday, for example. You might want to weight up the advantages
and
disadvantages of using month as string (where the localization will
have to
be the same as in System Prefs) or as number (where you'll have to use
the
same month-day-year order as in System Prefs). Unfortunately, the Unix
codes
for localized month-day order (%E, ETC.) don't work in OS X - you
always get
US version.
It is necessary because AppleScript is misinterpreting the standard
string produced by date. For example:
---------
set d to do shell script "date"
display dialog d & return & date d
---------
produces:
---------
Sat Jan 10 02:06:34 EST 2004
Saturday, January 10, 2004 10:02:06 AM
---------
The time reported by the date tool is 02:06:34, the time reported by
AppleScript's date coercion is 10:02:06. This is because AppleScript's
date coercion is mistakenly taking the 10 which leads the string
"02:06:34" as the hour and is parsing it as hour = 10, minute = 02,
second = 06. In order to get around this you either need to pull out
the time string yourself and apply it directly to the date object or
you need to provide a custom string format for the date tool so that it
is in a form that AppleScript can interpret better. The two script
examples I provided do just that.
- Ken
_______________________________________________
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.