Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

I was wondering if there is an apex date or datetime function to format a date/time to the ISO formatted timestamp "2007-04-05T12:30-02:00" or would this have to be created by another means?

Thanks.

1 Answer

0 votes
by (32.1k points)

DateTime format (string dataFormat) or format(string dataFormat, string timezone) methods can be used in Apex. It accepts a dataFormat string, which corresponds to a Java simple date format. You will need to define the correct format for ISO 8601.

Do take into account the timezone of the DateTime. In the below example, I have used the GMT format to avoid the 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()));

To learn in-depth about Workflow in Salesforce, sign up for an industry based Salesforce Admin certification.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 5, 2020 in Salesforce by dante07 (13.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...