• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UTC time with milliseconds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UTC time with milliseconds


  • Subject: Re: UTC time with milliseconds
  • From: Stan Cleveland <email@hidden>
  • Date: Mon, 23 Feb 2015 14:47:22 -0800

On Feb 23, 2015, at 12:27 PM, 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"

Is there another way. For example by using Objective-C?

Hi Jörgen,

Since the Mac shell does not handle milliseconds, you'll need to use Shane's ASObjC method or some shell-accessible tool. Do keep in mind Doug's warnings about accuracy. 

Here's a method using Ruby that should work regardless of your time zone:

set nowUTC to do shell script "ruby -e \"require 'date';
d = DateTime.now.new_offset(0);
print d.strftime('%Y-%m-%dT%H:%M:%S.%L')\""
--> "2015-02-23T22:38:16.858"

Execution time here is about 0.03 seconds, so Shane's method is at least 30 times faster. (I'm running Mtn. Lion 10.8.5 on a 2.5 GHz late 2011 MacBook Pro.)

HTH,
Stan C.

 _______________________________________________
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

  • Prev by Date: Re: UTC time with milliseconds
  • Next by Date: Re: UTC time with milliseconds
  • Previous by thread: Re: UTC time with milliseconds
  • Next by thread: Finder Scripting Qusetion
  • Index(es):
    • Date
    • Thread