I have a problem to convert String to DateTime and Insert it to a DateTime field in SF.
I found out that this is work :
String dateee = '2015/03/10 05:03:20';
DateTime date_time = DateTime.valueOfGmt(dateee.replaceAll('/','-'));
someObject__c someObjectInstance = new someObject__c(someObject_Date__c=date_time);
insert someObjectInstance;
But I get the DateTime from a JSON (String) : "03/10/2015 05:03:20" (dd/mm/yyyy) And when I put this text inside the code above I get an error of:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, someObject: invalid date: Sat Apr 06 05:03:20 GMT 9: [someObject__c]
I tried the below code to format it :
String dateee = '03/10/2015 05:03:20';
DateTime a = DateTime.valueOfGmt(dateee.replaceAll('/','-'));
a.formatGMT('DD-MM-YYYY\'T\'HH:mm:ss\'Z\'');
System.debug(a);
But it dosnt work..
I need to format it and insert it as a DateTime field. Can someone please help or post here some links? I tried to look for it but didn't find something valuable.