Skip to content

Instantly share code, notes, and snippets.

@fanaugen
Last active October 25, 2018 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanaugen/1852783 to your computer and use it in GitHub Desktop.
Save fanaugen/1852783 to your computer and use it in GitHub Desktop.
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