Where to get UTC to IST converter in apex?
I am getting this time from api response I need to display it in lightning:formatteddatetime, Sort those records based on date time so am doing this conversion in controller side
code:
string s = string.valueof(a2.get('server_modified'));
DateTime LDate = null;
if(s != null && s != ''){
s = s.replace('T', ' ');
s = s.replace('Z', '');
LDate = DateTime.valueof(s);
}
To get utc to ist converter - Salesforce stores the time in UTC but when we use apex:outputfield in the VF page, Salesforce converts the datetime to based on the user locale so you don't need to do anything. If you still have any other use case then I suggest use below code to convert Use Date.format() method and pass the time Zone. It will convert the time for you
//Get current date time in GMT format
Datetime dt = System.now();
//Convert it into Indian Standard Time(dtIST).
String dtIST = dt.format('yyyy-MM-dd HH:mm:ss', 'IST');
System.debug('dt-' + dt);
System.debug('dtIST-' + dtIST);