You need to sign in to do that
Don't have an account?
naveen reddy 19
How to the datetime to specified format
How to convert the datetime to specific format
Given date:
DateTime.Now()==> 2016-08-14 18:30:00
Expected date:
2014-01-01T00:00:00.015-04:00
Thanks,
Naveen
Given date:
DateTime.Now()==> 2016-08-14 18:30:00
Expected date:
2014-01-01T00:00:00.015-04:00
Thanks,
Naveen
DateTime.Now().format('yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX');
All Answers
Did you tried the fromat method?
DateTime.Now().format("yyyy-MM-dd\'T\'HH:mm:ss.SSSZ");
DateTime.Now().format('yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX');
Can you please also help me in converting this format to AST, as the expected datetime is in AST and we getting time in GMT.
Expected:
2014-01-01T00:00:00.015-04:00
Above code gives the follwing format.
DateTime.Now().format('yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX');==>2016-08-16T10:09:38.813+05:30.
Really appreciate your help.
Thanks in advance.
The format() method accepts timezone as second parameter. Just add the timezone as a parameter
DateTime.Now().format('yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX','AST')