Code for updating the date time value based on Time Zone in apex salesforce
public string getDateAsString(string originalDate,string Type)
{
String dateOutput='';
system.debug('inside getDateAsString');
if(originalDate!=null&&originalDate!='')
{
system.debug('**originalDate**'+originalDate);
if(Type=='date')
{
Datetime Datevalue = datetime.valueOf(originalDate);
dateOutput= Datevalue.format('MM/dd/yyyy');
}
else if(Type=='datetime')
{
Datetime Datevalue = datetime.valueOf( originalDate);
TimeZone tz = UserInfo.getTimeZone();
Double offsetDate=tz.getOffset(Datevalue)/3600000;
Datevalue=Datevalue.addHours(Integer.valueOf(offsetDate));
dateOutput= Datevalue.format('MM/dd/yyyy hh:mm:ss a');
}
}
system.debug('**dateOutput**'+dateOutput);
return dateOutput;
}
No comments:
Post a Comment