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 3843566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:57:22+00:00 2026-05-19T15:57:22+00:00

I need accurate time zone support in my BlackBerry app. Because it runs J2ME,

  • 0

I need accurate time zone support in my BlackBerry app. Because it runs J2ME, Joda Time is not an option. With the help of some others on SO I’ve figured out how to make Java’s built-in time zone support work for me, but it turns out that it still gets the switchover from daylight-savings to non-daylight-savings wrong. You can try it yourself, even on Java 6:

TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(zone);

calendar.set(2011, Calendar.MARCH, 13, 1, 0, 0);      
System.out.println(zone.getOffset(1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), calendar.get(Calendar.MILLISECOND)));

calendar.set(2011, Calendar.MARCH, 13, 6, 0, 0);
System.out.println(zone.getOffset(1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), calendar.get(Calendar.MILLISECOND)));

calendar.set(2011, Calendar.MARCH, 13, 23, 59, 59);
System.out.println(zone.getOffset(1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), calendar.get(Calendar.MILLISECOND)));

calendar.set(2011, Calendar.MARCH, 14, 0, 0, 1);
System.out.println(zone.getOffset(1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), calendar.get(Calendar.MILLISECOND)));

Switchover in 2011 is on March 13th, at 2am, but Java has it at midnight of March 14th. That means it’s wrong for almost an entire day. That’s unacceptable.

I have embarked upon implementing my own tzdata parser based on this, and shipping the tzdata files with my app, but I’m wondering if there is a better way. Do you know one? I can’t be the first one to hit this problem, can I?

  • 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-05-19T15:57:23+00:00Added an answer on May 19, 2026 at 3:57 pm

    I figured it out. Java is not to blame, I am.

    The problem is that I used calendar.get(Calendar.MILLISECOND) for the last parameter of TimeZone.getOffset(). That value is the millisecond portion of the date in the calendar, but what TimeZone.getOffset() expects is the number of milliseconds that have passed over the course of the entire day.

    This is the corrected code:

    calendar.set(2011, Calendar.MARCH, 13, 1, 0, 0);      
    int millis =
        calendar.get(Calendar.MILLISECOND) +
        calendar.get(Calendar.SECOND) * 1000 +
        calendar.get(Calendar.MINUTE) * 60 * 1000 +
        calendar.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000;
    System.out.println(zone.getOffset(1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_WEEK), millis));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some regular expressions help. So far I have my code working to allow
Some time in the near future I will need to implement a cross-language word
need some help! I'm trying to write some code in objective-c that requires part-of-speech
I need a very accurate way to time parts of my program. I could
I need accurate time which my website should be able to access thru internet
I have this code to wait for some time to get high accurate data:
I need high-resolution (more accurate than 1 millisecond) timing in my application. The waitable
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need help with a query that I wrote: I have three tables Company id

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.