Thursday, August 16, 2018

#1 2018-06-08 09:09:03 am

ame
Member
Registered: 2011-06-28
Posts: 178

Date and time that include Milliseconds

Hi I would like to include in my detailed log of app the time stamp with milliseconds when a VerboseLog() handler is called.
At the moment I can write something like YYYYMMDD-HHMMSS but i miss the milliseconds.
Anyone has a solution using pure AppleScript or Asoc?

Stefano - Ame


Filed under: milliseconds

Offline

 

#2 2018-06-08 10:25:03 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 282

Re: Date and time that include Milliseconds

I don't know of a way to do it in "pure" Applescript, but you can do it with a do shell script and Perl.

Applescript:

set UNIXtime to do shell script "perl -e 'use Time::HiRes qw(time); print time'"


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#3 2018-06-08 01:15:52 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4620

Re: Date and time that include Milliseconds

With ASObjC:

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"

set now to current application's class "NSDate"'s |date|()
set dateFormatter to current application's class "NSDateFormatter"'s new()
tell dateFormatter to setDateFormat:("yyyyMMdd-HHmmss.SSS")
set timeStamp to (dateFormatter's stringFromDate:(now)) as text

However, I don't imagine the clock on your computer will be that accurately set.  smile


NG

Online

 

#4 2018-06-08 02:31:07 pm

ame
Member
Registered: 2011-06-28
Posts: 178

Re: Date and time that include Milliseconds

Hi Nigel,

W o n d e r f u l ! ! !
Exactly what I need. Thank you!!!

Stefano

Offline

 

#5 2018-06-10 07:51:57 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2794
Website

Re: Date and time that include Milliseconds

With AppleScript Toolbox:

Applescript:

AST format date "yyyyMMdd-HHmmss.SSS"

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)