Created
August 31, 2015 21:04
-
-
Save darrenpmeyer/87beea84082bebad6296 to your computer and use it in GitHub Desktop.
Convert AppleScript date objects to UNIX timestamp or POSIX date format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- convert an AppleScript Date object to a POSIX date CCYYMMDDHHmm.SS | |
on posixDate(datetime) | |
-- date -j -f "%A, %B %e, %Y at %I:%M:%S %p" "Tuesday, September 1, 2015 at 11:00:00 AM" +%Y%m%d%H%M | |
set command to "date -j -f '%A, %B %e, %Y at %I:%M:%S %p' '" & datetime & "'" | |
set command to command & " +%Y%m%d%H%M.%S" | |
set thePosixDate to do shell script command | |
return thePosixDate | |
end posixDate | |
-- convert an AppleScript Date object to a UNIX timestamp (seconds since epoch) | |
on unixDate(datetime) | |
set command to "date -j -f '%A, %B %e, %Y at %I:%M:%S %p' '" & datetime & "'" | |
set command to command & " +%s" | |
set theUnixDate to do shell script command | |
return theUnixDate | |
end unixDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this is broken for me, as Apple recently replaced the space between
%S
and%p
with a non-breaking space. I had to change%S %p
to%S %p
for this to work. (Looks the same but the former usesU+0020
and the latterU+202F
.)