Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:27:13+00:00 2026-06-10T15:27:13+00:00

I would like to save some user timezone in a Daylight saving proof format.

  • 0

I would like to save some user timezone in a Daylight saving proof format.
My goal is to get the correct GMT offset whenever the code gets executed.
In order to figure out my best option, I wrote the following:

ArrayList<String> list = new ArrayList<String>();
list.add( "EST");
list.add( "EDT");
list.add( "America/New_York");
long now = System.currentTimeMillis();
for( String tzID: list) {
    TimeZone tz = TimeZone.getTimeZone( tzID);
    System.out.println( tzID + " now=" + tz.getOffset( now) / 3600000 + " / +182=" + tz.getOffset( now + ( 182 * 86400000)) / 3600000);
}

For short, give me the offset now and in 182 days
Executed September 3rd, the output is

EST now=-5 / +182=-5
EDT now=0 / +182=0
America/New_York now=-4 / +182=-4

This is unexpected for several reasons
1) Why is America/New_York not giving -4/-5 ?, Isn’t it supposed to be date sensitive?
2) Why does EDT == UTC?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:27:15+00:00Added an answer on June 10, 2026 at 3:27 pm

    One problem you have is that 182 * 86400000 overflows. If you use

    long now = System.currentTimeMillis();
    for( String tzID: "EST,EDT,America/New_York".split(",")) {
        TimeZone tz = TimeZone.getTimeZone( tzID);
        System.out.println( tz.getDisplayName() + " now=" + tz.getOffset( now) / 36e5 
                         + " / +182=" + tz.getOffset( now + 182 * 86400000L) / 36e5);
    }
    

    prints

    Eastern Standard Time now=-5.0 / +182=-5.0
    Greenwich Mean Time now=0.0 / +182=0.0
    Eastern Standard Time now=-4.0 / +182=-5.0
    

    If you look at the javadoc and source for getTimeZone you can see

     * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
     * cannot be understood.
    
    public static synchronized TimeZone getTimeZone(String ID) {
    return getTimeZone(ID, true);
    }
    
    private static TimeZone getTimeZone(String ID, boolean fallback) {
    TimeZone tz = ZoneInfo.getTimeZone(ID);
    if (tz == null) {
        tz = parseCustomTimeZone(ID);
        if (tz == null && fallback) {
        tz = new ZoneInfo(GMT_ID, 0);
        }
    }
    return tz;
    }
    

    In short, EDT is not recognised so it becomes GMT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my User model to sanitize some input before before save. For
I would like to save some user-specific data in my iPhone app. I was
I have a plist where I would like to save a some response details
I've made some experimental code that I would like to save in the repository,
I am studying javascript and I've got some problems. I would like to save
I would like to download an mp3 file from some site, save it to
So I would like to save some data on external storage on android. And
I would like to save and load a set of images in Octave /
I would like to save query result into redis using JSON serialization and query
I would like to save and restore the state of a WinForms Form ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.