Why is the salesforce datetime format different in the UI and DB?
Why is there a datetime format so different as compared to what I see in the UI vs SOQL/APEX and I can not figure out what is going on. Can anybody please explain what I'm doing wrong here?
In the UI this is what I see:
5/27/2021 6:30 AM
and when I query I see this:
2021-05-27T11:30:00.000+0000
when I ran the apex code I see this:
2021-05-27 11:30:00
String data = '2021-05-27T11:30:00.000+0000'; Datetime dt = (DateTime)JSON.deserialize('"' + data + '"', DateTime.class); system.debug( dt);
My question, why is it not showing what is in the UI?
The UI format is just a more user-friendly format, shown in your preferred time zone, converted from GMT on the back end.
The results of your query are the IS0-8601 format, how it is stored on the back end.
The output of your Apex code is the default formatting of the Datetime primitive data type.
Additional Resource on salesforce Datetime format methods on Apex: https://developer.salesforce.com/docs/atlas.en-us.232.0.apexref.meta/apexref/apex_methods_system_datetime.htm