function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Damien_Damien_ 

DateTime formatting issues with Time Zones

currently I have

DateTime.now().format('MM/dd/yyyy hh:mm a', 'EST');

 

but I would like to have 

DateTime.now().format('MM/dd/yyyy hh:mm a', 'ET');

 

The issue is that when I put ET as the timezone it defaults the timezone to GMT since ET is not a correct time zone.  How do I accomplish this?

Best Answer chosen by Admin (Salesforce Developers) 
TheSwamiTheSwami

 

The format follows the Java standard - In your example:
DateTime.now().format('MM/dd/yyyy hh:mm a', 'US/Eastern');

 

All Answers

bob_buzzardbob_buzzard

Can you tell us what timezone ET is intended to represent?  

Damien_Damien_

Eastern Time (ET)

bob_buzzardbob_buzzard

ET isn't a valid timezone as far as Java is concerned - is there a reason why EST doesn't handle this for you?

TheSwamiTheSwami

 

The format follows the Java standard - In your example:
DateTime.now().format('MM/dd/yyyy hh:mm a', 'US/Eastern');

 

This was selected as the best answer
Damien_Damien_

I believe EST uses daylight savings and ET doesn't.  The client specifically asked me to display time as ET and not EST.

Damien_Damien_

Hmmmm I think this is what I was thinking of.  Thank you!

Saleforce's manSaleforce's man

Could you show me how to adjust or format system date time to YYYY/MM/DD hh:mm:ss. Now my salesforce only display datetime field as YYYY/MM/DD hh:mm without second.

 

Damien_Damien_

I would assume all you need to do is add the :ss

 

DateTime.now().format('MM/dd/yyyy hh:mm:ss a', 'US/Eastern');