Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple date parser
(*
* Example of a simple string-to-date parser.
* Uses AppleScript's text item delimiters to split the input string
*)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"-", "T", ":", "Z"}
set dateString to "2011-12-23T08:00:00Z" -- what's Z for?
set pieces to text items of dateString
set d to current date
set {year of d, month of d, day of d, time of d} to ¬
{item 1 of pieces, item 2 of pieces, item 3 of pieces, ¬
((item 4 of pieces) as number) * hours + ¬
((item 5 of pieces) as number) * minutes + ¬
((item 6 of pieces) as number)}
d -- is now set to December 23, 2011, 08:00:00
set AppleScript's text item delimiters to tid -- because I'm a well-behaved script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment