0

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

2
  • 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
    Commented Mar 28, 2019 at 23:40
  • Yeah, that make sense. I will do that.
    – Ajay
    Commented Mar 29, 2019 at 8:54

1 Answer 1

0

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(); 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .