Skip to Content

TheBlogReaders.com

Salesforce.com Learn & Share

How to convert DateTime to UTC time using Apex Class?

Be First!

How to convert DateTime to UTC time using Apex Class?

Difference Between GMT and UTC:
The Difference Between GMT and UTC. Greenwich Mean Time (GMT) is often interchanged or confused with Coordinated Universal Time (UTC). But GMT is a time zone and UTC is a time standard. The Royal Observatory in the UK. The Royal Observatory in Greenwich, London, United Kingdom.

public DateTime getUTCDateTime(DateTime dt){
Datetime GMTDate = Datetime.newInstanceGmt(
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second());
return GMTDate;
}

System.debug(‘UTC time ‘+getUTCDateTime(System.now()));
Refer DateTime methods:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm

(1)

Previous
Next

Leave a Reply