function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SpongeBob_2009SpongeBob_2009 

Apex: Current time, Milli Second Precision?

I want to get as much time precision from the system as possible...then covert to sting.

 

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

Well, in Apex:

 

Datetime x =  Datetime.now();

Integer m = x.milliseconds();

 

You can then convert it to a String in any number of formats, etc.

 

or  Datetime.getTime returns the offset from 1/1/70 in milliseconds.

 

 

It's funny though, I've always thought of Sting as more of a musician than some sort of spy.  I'm not sure why he'd need you to send himmillisecond values through some secret channel? 

 

Best, Steve.

All Answers

SteveBowerSteveBower

Well, in Apex:

 

Datetime x =  Datetime.now();

Integer m = x.milliseconds();

 

You can then convert it to a String in any number of formats, etc.

 

or  Datetime.getTime returns the offset from 1/1/70 in milliseconds.

 

 

It's funny though, I've always thought of Sting as more of a musician than some sort of spy.  I'm not sure why he'd need you to send himmillisecond values through some secret channel? 

 

Best, Steve.

This was selected as the best answer
Yatendra GoelYatendra Goel
It is `millisecond()` and not `milliseconds()`:

`Long start = Datetime.now().millisecond()`