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

String to Datetime



I have a string of the format - 2013-01-10T18:01:43.017+0000.
What is the best way to convert the above string format to Datetime?



Shailesh DeshpandeShailesh Deshpande

you can use the datetime.valueOf(string)

however, the string format needs to be yyyy-mm-dd hh:mm:ss
so you will need to prbably convert your string to above format and then use datetime.valueOf() method.
Jia HuJia Hu
You can use
String str =;
to get your local datetime format,
and covert your string to this format,
then use
Datetime dt = Datetime.parse(str);
to turn the String to Datetime.