function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
indyindy 

Convert 24 hours date time to 12 hours date time format

Hi,

I need to convert and assign 24 hours date time value to custom date time field.
For Example, in my apex code I am getting the date time value as ‘2019-03-12 14:38:00’, I need to convert and assign this value to custom date time field as 2019-03-12 02:38 PM in the Salesforce UI.
The format methods that I used so far converts '2019-03-12 14:38:00' to
'2019-03-12 10:38 AM' which is my user time zone.
 
I am not looking for time zone conversion, just format the date time.

Thanks,
Indrasen
Raj VakatiRaj Vakati
try like this ..use format method 
 
for(Account obj : [SELECT Id, CreatedDate FROM Account LIMIT 20]){
    Datetime myDateTime = obj.CreatedDate;
    String dtConverted = myDateTime.format('MM/dd/yyyy h a');
    system.debug('======'+dtConverted);
}

https://www.xgeek.net/salesforce/date-format-and-datetime-format/