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
bharath11rbharath11r 

Parse zulu time string to DateTime error

I am getting a string something like from soap response 2012-02-21T11:27:54.134Z

and when i try to parse it using Datetime.Parse('2012-02-21T11:27:54.134Z') it's saying invalid time.

Could anyone please help me with this.

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
bharath11rbharath11r

That will never work in my case because its an expiration field and I cannot cast it is as Date.

Above code works because its date field but try chaning it to DateTime and you will see my errors.

 

 

Alrite after pulling my hair for long time I got the answer.

 

string s = '2012-02-21T11:27:54.14Z';
System.Debug('DateValue is '+Datetime.valueOf(s.replace('T',' ')));

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

date dt=date.valueof('2012-02-21T11:27:54.14Z');
system.debug('@@'+dt);

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

bharath11rbharath11r

That will never work in my case because its an expiration field and I cannot cast it is as Date.

Above code works because its date field but try chaning it to DateTime and you will see my errors.

 

 

Alrite after pulling my hair for long time I got the answer.

 

string s = '2012-02-21T11:27:54.14Z';
System.Debug('DateValue is '+Datetime.valueOf(s.replace('T',' ')));

 

This was selected as the best answer