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
vvvvvv 

Format specifiers for parsing datetime strings

I am surprised to see that there is no way to specify format specifier to parse a date time string.

 

I get the date time from a webservice response in the following fashion ''Jun 30 2010  8:00AM'. When I use a datetime.parse on this it says invalid date/time.

 

Ideally I should be able to specify a format specifier along with it possibly like 'MMM dd yyyy hh:mmp' or something to that extent.

 

Is there really no format specifier in APEX? Do I have to parse the string myself!

 

Thanks

v

Ankit AroraAnkit Arora

Hi,

 

Here is apex code to format the datetime :

 

 

DateTime dt = System.now();
String str = dt.format('MM d,yyyy') ;
System.debug('Str ::::' + str) ;

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page