I have a DateTime field which shows proper time on UI, I know behind the scene it is GMT format. However I would like to populate same format as it displays on UI in a text field along with some text.

enter image description here

  • 1
    Since different users accessing your UI may have different time zones, pre-rendering the value into a string is not a good idea. Better to have the system dynamically render the date time on demand.
    – Phil W
    Mar 28, 2019 at 23:40
  • Yeah, that make sense. I will do that.
    – Ajay
    Mar 29, 2019 at 8:54

1 Answer 1


Yes, formula is not valid for this requirement, so I used trigger to update the text field. date.format() is the savior.

String timeZone = UserInfo.getTimeZone().getID();
Datetime dateGMT = info.Info_Session_Date__c;
Datetime dateTimeValue = Datetime.valueOf(dateGMT);
string convertedString = dateTimeValue.format(); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.