Skip to main content
1 of 4

deserializing your datetime (both utc & ISO) in datetime.class should solve the issue. JSON.desrialize('datetime' , Datetime.class);

i have tested both format in anynomous block and it is working fine.

Datetime effectiveDt = (Datetime) JSON.deserialize('1985-01-01 00:00:00.000',Datetime.class);
system.debug(Date.newInstance(effectiveDt.yearGmt(), effectiveDt.monthGmt(), effectiveDt.dayGmt()));


Datetime effectiveDtISO = (Datetime) JSON.deserialize('1985-01-01T00:00:00',Datetime.class);
system.debug(Date.newInstance(effectiveDtISO.yearGmt(), effectiveDtISO.monthGmt(), effectiveDtISO.dayGmt()));

Credits go to this thread which i have referred : Parsing an ISO 8601 timestamp to a DateTime