Re: UTC time with milliseconds
Re: UTC time with milliseconds
- Subject: Re: UTC time with milliseconds
- From: Shane Stanley <email@hidden>
- Date: Tue, 24 Feb 2015 09:30:21 +1100
On 24 Feb 2015, at 7:27 am, Jörgen Stahle <email@hidden> wrote:
Does anyone know a nice way to get UTC time with milliseconds? What I would like is a timestamp like this: 2015-02-23T20:56:31.471
It would be nice to use do shell script "date -u '+%Y-%m-%dT%H:%M:%S.%N’" - but the ”N” in that command does not work in BSD, as in other Unix systems. It returns "2015-02-23T20:26:10.N"
You could always use ASObjC:
use framework "Foundation"
set theNSDateFormatter to current application's NSDateFormatter's alloc()'s init() theNSDateFormatter's setDateFormat:"yyyy-MM-dd'T'HH:mm:ss.SSS" return theNSDateFormatter's stringFromDate:(current application's NSDate's |date|()) Result of Main Script: --> (NSString) "2015-02-24T09:22:00.865"
If you're doing it repeatedly, it would be preferable to make just one date formatter and reuse it, because that's what takes most of the time.
OTOH, it takes less than a millisecond as it is on my Mac, whereas the the shell script alternative takes about six milliseconds.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden