0

I'm receiving a datetime string as a response in postman from a service. but when I'm converting the string value to date time. The value is getting converted to date time as expected but it is displaying the user time zone queried or used in table. Is it not possible to convert the date time value from string to dateTime and store in date Time field with the same value?

3
  • How are you "converting" the string to datetime? What format is the string in to begin with? It is indeed possible to convert to a GMT-based date time, but we need to know where you started from.
    – sfdcfox
    Apr 11 at 12:43
  • The string format is "2022-04-07T17:14:04.75Z"
    – prasanth
    Apr 11 at 13:02
  • I'm converting from string to date timy by the following code: String replaceString = transDateString.replaceAll('[TZ]',' '); myNewRow.put('TransDate',DateTIme.ValueOf(replaceString));
    – prasanth
    Apr 11 at 13:04

1 Answer 1

1

Date.valueOf is the wrong method, as it is meant to parse times in the user's time zone. You can use Date.valueOfGmt instead. Alternatively, consider JSON.deserialize:

DateTime transDateTime = (DateTime)JSON.deserialize(transDateString, DateTime.class);

This will allow you to parse the date time in GMT without any string manipulation.

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.