Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Calendar TimeZone for US Stock Market

I am doing Android programming related to US NYSE & NASDAQ stock market. So far I know that they are using Eastern Time (ET). Stock market opens at 9.30AM ET, closes at 4pm ET.

In order to check stock market is currently open / close, I want to check whether current time is within 9.30am - 4pm.

Is the below code correct, to get user time in ET timezone?

Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("US/Eastern"));

As I read, Eastern Time (ET) observe Daylight saving. In summer it uses EDT which is UTC-4, whereas in winter it uses EST which is UTC-5. So NYSE & NASDAQ is using ET timezone?

I want to make sure my comparison of 9.30am - 4pm is using same timezone as NYSE & NASDAQ stock market.

like image 397
Shuwn Yuan Tee Avatar asked Jan 23 '26 05:01

Shuwn Yuan Tee


1 Answers

Instead of the outdated id "US/Eastern", I would choose "America/New_York" according to the tzdb maintained by IANA.

This timezone takes into account daylight saving during summer (but not winter) and can hence be applied throughout the whole year.

Wikipedia indicates that NYSE & NASDAQ stock market uses this timezone, too.

By the way, I would use new GregorianCalendar() instead of Calendar.getInstance() to make sure that you get the right calendar (relevant if you are in Thailand).

Evaluating the open-condition might look like this (half-open interval for local time "9:30/16:00"):

    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    boolean open = (hour > 9 || (hour == 9 && minute >= 30)) && (hour < 16);
like image 150
Meno Hochschild Avatar answered Jan 24 '26 19:01

Meno Hochschild



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!