As we already know based on user local and company info date time will be displayed by default.
However we need to convert date time from one format to another. Below is some code snippet for this .
DateTime CurentTime = system.now();
String TimeZones = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
List<String> lststrsplit = TimeZones.substring(12,TimeZones.length()).split('\\(',2);
System.debug('Printing--lststrsplit-'+lststrsplit);
string strTimeZone = lststrsplit[1].substring(0,lststrsplit[1].length()-1);
System.debug('Printing--strTimeZone-'+strTimeZone);
system.debug(CurentTime+'abc#');
string strCurrentTime = CurentTime.format('YYYY-MM-dd HH:mm:ss', strTimeZone);
Datetime dateCurrentTime = Datetime.valueof(strCurrentTime);
System.debug('Printing--dateCurrentTime-'+dateCurrentTime);
However we need to convert date time from one format to another. Below is some code snippet for this .
DateTime CurentTime = system.now();
String TimeZones = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
List<String> lststrsplit = TimeZones.substring(12,TimeZones.length()).split('\\(',2);
System.debug('Printing--lststrsplit-'+lststrsplit);
string strTimeZone = lststrsplit[1].substring(0,lststrsplit[1].length()-1);
System.debug('Printing--strTimeZone-'+strTimeZone);
system.debug(CurentTime+'abc#');
string strCurrentTime = CurentTime.format('YYYY-MM-dd HH:mm:ss', strTimeZone);
Datetime dateCurrentTime = Datetime.valueof(strCurrentTime);
System.debug('Printing--dateCurrentTime-'+dateCurrentTime);
No comments:
Post a Comment