Re: parsing Unix date
Re: parsing Unix date
- Subject: Re: parsing Unix date
- From: Graff <email@hidden>
- Date: Fri, 09 Jan 2004 13:59:07 -0500
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"
----------
Now if you are handed an arbitrary date string and you don't have
control over the format then things can get a bit tougher. Obviously
AppleScript does a decent job of parsing date strings but it can't
handle every case. Here's a way of parsing out just the time portion
through the use of the command-line tool awk.
--------
set d to (do shell script "date")
---> "Fri Jan 9 13:53:33 EST 2004"
set g to do shell script "echo " & d & "|awk 'BEGIN { RS = \" \" }
/.*:.*:.*/ { print }'"
---> "13:53: 33"
set theDate to date d
---> date "Friday, January 9, 2004 9:13: 53 AM"
set time of theDate to time of date g
---> 50013
display dialog (date string of theDate) & return & (time string of
theDate)
---> "Friday, January 9, 2004"
---> "1:53:33"
--------
You could probably do the same thing with any OSAX that lets you use
regular expressions.
- Ken
On Jan 9, 2004, at 9:48 AM, Michael Grant wrote:
set d to (do shell script "date") --> "Fri Jan 9 01:00:02 CST 2004"
date d --> date "Friday, January 9, 2004 9:01:00 AM"
What's wrong with this picture?
More to the point, how can I transform a Unix date to an AppleScript
date more accurately?
_______________________________________________
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.