String formatedDt = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
I want to used this string in dyamic SOQL but it gives me formatted string in localtimezone, can anyone help me how do i get it in GTM ?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityUse DateTime's formatGMT to format the time according to your specs in GMT.
String formatedDt = dt.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
you can use the dateGMT() method:
dateGMT()
Return the Date component of a Datetime in the GMT time zone. Signature
public Date dateGMT()
Return Value
Type: Date
Example:
DateTime myDateTime = DateTime.newInstance(2006, 3, 16, 23, 0, 0);
Date myDate = myDateTime.dateGMT();
Date expected = Date.newInstance(2006, 3, 17);
System.assertEquals(expected, myDate);
from the Apex developer Guide