I have the following dateTime values
2023-11-05 09:16:14 2023-11-07 09:16:14
Im getting them properly from a table using Apex code
DateTime startDt = informaticaAuditTableRecords[0].startDate;
DateTime endDt= informaticaAuditTableRecords[0].EndDate
I have now converted them into a particular string format below using this snippet
String d1;
String d2;
d1 = startDt.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
d2 = endDt.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
Problem is when Im trying to convert this String back to the DateTime Format using below Snippet
DateTime dt1 = DateTime.valueOfGmt(d1);
DateTime dt2 = DateTime.valueOfGmt(d2);
I am getting the below error System.TypeException: Invalid date/time: 2023-11-05T09:16:14Z
I am unable to parse this string properly to Date Time How can I achieve this?
(Datetime) JSON.deserialize('"' + d1 + '"', Datetime.class)
? JSON expects date/time values to be in UTC anyway so I think this should work...