+ Start a Discussion
kirubakaran viswanathankirubakaran viswanathan 

How to split UTC datetime to Date and time based on Country in Opportunity

I have the start and end DateTime field in Opportunity, I need to split that into date and time based on customers' country in the record.

Eg: UTC : 2021-04-26T09:00:00.000+0000

Country is UK
Output:
Date : 26-04-2021
Time : 10 AM

If the country is Germany
Output:
Date : 26-04-2021
Time : 11 AM
 
SwethaSwetha (Salesforce Developers) 
HI Viswanathan,
You can make use of the FORMAT() that converts and displays a given datetime into user's locale 

Example: I am passing val in UTC and it returns in IST timezone
String val = '2020-11-21T13:00:12.421Z';
DateTime date1 = (DateTime)Json.deserialize('"'+val+'"', DateTime.class);
String s=date1.format();
System.debug('===='+s);
//output: ====11/21/2020 6:30 PM

If this information helps, please mark the answer as best. Thank you

kirubakaran viswanathankirubakaran viswanathan
Hi Swetha, Thank you for your note. The solution is not for Users. It is for customers(out of salesforce). I need to refer to those fields in the email template, where the date and time should be converted based on the country's timezone.
SwethaSwetha (Salesforce Developers) 
Is the country a field on opportunity object?

Related: https://developer.salesforce.com/forums/?id=906F000000098DmIAI
Thanks