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
sun tarsun tar 

How to convert system.now to 2014-12-23T06:00:00.000Z format?

Hi all,

How to convert the system.now() date time format (2014-12-23 13:19:13) to the following format 2014-12-23T06:00:00.000Z ?

Thanks.
Anoop yadavAnoop yadav
Hi,
Try the below Code.
DateTime dt = system.now();
System.debug('DATETIME:'+dt.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\''));

 
sun tarsun tar
that again returns a string right and if u parse it then it would again be in the system.now format
Anoop yadavAnoop yadav
Hi,
yes this is in String Format.
But using parse method you can not convert to DateTime again.
Kislay KumarKislay Kumar
For those who are here searching correct GMT format, try below:
Datetime d = System.now();  //Returns GMT time, also SF stores all datetime in objects in GMT format only.
String dt = String.valueOf(d.dateGmt())+'T'+String.valueOf(d.timeGmt());