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
Prasanna K 7Prasanna K 7 

Convert String containing date time to a DateTime in APEX

I have a String dtme = "20150901174244"(YYYYMMDDHHMMSS)  I need to convert it to a DateTime in APEX like 01/09/2015 5:42 PM.   Would someone be able to show me the code to do this properly?

 any help is much appreciated.
Tugce SirinTugce Sirin
Datetime dt = Datetime.newInstance(Integer.valueOf(dtme.substring(0,4)), Integer.valueOf(dtme.substring(4,6)), Integer.valueOf(dtme.substring(6,8)), Integer.valueOf(dtme.substring(8,10)), Integer.valueOf(dtme.substring(10,12)), Integer.valueOf(dtme.substring(12,14)));

Above code would work.
prasanna kovuriprasanna kovuri
working perfect.