How To Format Datetime like 2017-01-10T14:53:55.000+0000?
Using the example given in the DateTime class and calling the formatGMT(string)
method with a formatting string found in the Java SimpleDateFormat examples:
DateTime myDateTime = DateTime.newInstance(1993, 6, 6, 3, 3, 3);
String formatted = myDateTime.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ');
system.debug(formatted);
Produces this result:
15:41:47:003 USER_DEBUG [3]|DEBUG|1993-06-06T10:03:03.000+0000
C# String.ToString()
Please don't vote me down, I kept getting dumped to this post trying to figure out how to do this with C#. Here's how I did it:
String iso8601DateFormat = "yyyy-MM-dd'T'HH:mm:ss.FFFK";
DateTime scheduled__c = DateTime.Now.ToString(iso8601DateFormat);