Salesforce Apex: ISO timestamp format function

I was wondering if there is a date or date or time function for formatting the date / time in timestamp format, formatted in ISO format "2007-04-05T12: 30-02: 00", or should it be created in another way?

Thanks.

+4
source share
1 answer

In Apex, you can use the DateTime format(string dataFormat) or format(string dataFormat, string timezone) methods. It takes a string dataFormat, which corresponds to a simple Java date format. You will need to determine the correct format for ISO 8601.

Also consider the time zone of DateTime. In the example below, I used formatGMT to avoid timezone offset.

 System.debug(datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'')); 

Alternatively, you can use the JSON serializer.

 System.debug(json.serialize(datetime.now())); 
+12
source

Source: https://habr.com/ru/post/1499941/


All Articles