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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:35:17+00:00 2026-05-29T15:35:17+00:00

I’ve written a Java app in which I start the date at Jan 1

  • 0

I’ve written a Java app in which I start the date at Jan 1 00:00 of a particular year. Then I increment the day 355 times and print out the results along the way. I was trying to understand how the timezones work around daylight savings time, and if adding 1 day would shift the time from midnight to 1am when crossing into daylight savings. My code looks like:

TimeZone tz = TimeZone.getDefault();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");
sdf.setTimeZone(tz);
Calendar cal = Calendar.getInstance(tz);
cal.set(2008, 0, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
for ( int i = 0; i < 355; i++ ) {
    System.out.println(sdf.format(cal.getTime()));
    cal.add(Calendar.DAY_OF_MONTH, 1);
}

When running in my default time zone (US Eastern), the output looks like as I would expect:

01/01/2008 00:00:00 EST
01/02/2008 00:00:00 EST
01/03/2008 00:00:00 EST
01/04/2008 00:00:00 EST
...

and when I cross into daylight savings time, I get

03/10/2008 00:00:00 EDT
03/11/2008 00:00:00 EDT
03/12/2008 00:00:00 EDT

When I use a timezone that observes Eastern European summer time, (in this case, I chose the Africa/Cairo timezone) I get the output:

01/01/2008 00:00:00 EET
01/02/2008 00:00:00 EET
01/03/2008 00:00:00 EET
01/04/2008 00:00:00 EET
01/05/2008 00:00:00 EET

but when I cross into Eastern European summer time, I get:

04/25/2008 01:00:00 EEST
04/26/2008 01:00:00 EEST
04/27/2008 01:00:00 EEST

And strangely when EEST ends, I still get

08/29/2008 01:00:00 EET
08/30/2008 01:00:00 EET

I’m confused as to why these timezones behave differently and if it is a bug with Africa/Cairo timezone, or if I am misunderstanding how the timezones work…

Any insight into this would be appreciated.

  • 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-29T15:35:18+00:00Added an answer on May 29, 2026 at 3:35 pm

    The Cairo time zone changes into daylight saving time at midnight – so the hour between midnight on April 25th 2008 was skipped… the wall clocks went:

    04/24/2008 23:59:58
    04/24/2008 23:59:59
    04/25/2008 01:00:00
    04/25/2008 01:00:01
    

    Try adding one day at a time from 2am in the US Eastern time zone and you’ll see the same thing – it’ll go to 03:00 at some point.

    It’s not clear what you’re trying to achieve exactly – I tend to think it’s better to either add “a number of experienced milliseconds” to a date/time in a particular time zone, or add “a number of logical milliseconds” to a local date/time, which doesn’t take time zones into account. When you convert from local time to time in a specific zone, you need to consider the possibility of ambiguity (one local time occurring twice) or skipping (one local time not occurring at all).

    For added fun, last year Samoa skipped December 30th entirely, due to changing its time zone from -14 to +10…

    EDIT: Oh, and my standard recommendation applies: ditch java.util.Calendar/Date, and go with Joda Time

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am writing an app with both english and french support. The app requests

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.