Here is the simple steps to convert a datetime value to the specific timezone in salesforce,
Step 1:
Build a specific date
Step 2:
Build a specific time.
Step 3:
Build DateTime instance and pass Date and Time values in parameter.
Step 4:
Convert the specified time to GMT using timeGMT() method.
Step 5:
Build a datetime with GMT and pass Date and Converted GMT time values in the parameter.
Step 6:
To convert a datetime to the specific timezone, provide the datetime format along with time zone.
Step 1:
Build a specific date
Step 2:
Build a specific time.
Step 3:
Build DateTime instance and pass Date and Time values in parameter.
Step 4:
Convert the specified time to GMT using timeGMT() method.
Step 5:
Build a datetime with GMT and pass Date and Converted GMT time values in the parameter.
Step 6:
To convert a datetime to the specific timezone, provide the datetime format along with time zone.
- Date myDate = date.newinstance(2015, 10, 20);
- Time myTime = Time.newInstance(23, 35, 0, 0);
- DateTime dt = DateTime.newInstance(myDate, myTime);
- Time myGmtTime = dt.timeGMT();
- System.debug('GMT Time'+dt.timeGMT());
- DateTime dtt = DateTime.newInstanceGmt(myDate, myGmtTime);
- String strConvertedDate = dtt.format('MM/dd/yyyy HH:mm:ss', 'Asia/Kolkata');
- System.debug('Converted time'+strConvertedDate);
Reference:
No comments:
Post a Comment