tags:

views:

453

answers:

3

Calendar.getInstance(TimeZone.getTimeZone("GMT+1")).get(Calendar.HOUR_OF_DAY) is an hour "slow", (possibly because they does not detect the daylight saving +1 hour.) In J2SE, there are a lot of available time zones (Europe/Budapest too, and it works perfectly), but in J2ME there are only GTM and UTC.
How can I get the "right" hour?

+2  A: 

You've asked for "GMT+1" which is a fixed time zone - no daylight saving is applied. If you need to apply daylight saving and J2ME doesn't supply any DST time zones, you're going to have to work out that logic yourself :(

(In other words, it sounds like J2ME is behaving correctly, but it doesn't support the feature you want it to.)

Jon Skeet
Aren't *all* time zones fixed? We just change time zones during the summer, we don't move the time within those time zones...
BenAlabaster
@balabaster: No, we don't change time zone. Our time zone changes its UTC offset, that's all. For instance, I am in the time zone with Olsen ID "Europe/London". That is UTC+0 in winter, and UTC+1 in summer.
Jon Skeet
(At least within every sensible time zone API I've used :)
Jon Skeet
I thought that we would be GMT (UTC+0) during the winter months and BST (UTC+1) during the summer months. GMT doesn't change and BST doesn't change, but we switch between the two. I guess I could be mistaken though...
BenAlabaster
Of course, I don't suppose this is really pertinent to the original question, so I can read up on that in my own time :P
BenAlabaster
I just re-read your comment and I completely missed "API"... I was talking about the real world so we're talking cross purposes. Of course in the API world, we just change our offest... what was I thinking?
BenAlabaster
+1  A: 

I just had this issue with a completely different application - it was a mobile application, but it turned out to be a paradigm issue with my way of thinking, not a programmatic problemn at all... I wonder if this is the same issue you're having.

Currently England is on British Summer Time, so what people often consider GMT is the time it currently is in England... which is not always GMT. BST is GMT+1, which (depending on your location and whether or not you use daylight savings) could cause issues. This would also affect the date if GMT is a day behind.

For instance, I'm presently in Toronto, which is currently GMT-4, but is 5 hours behind London which caused me a great deal of confusion. I think what added to the confusion is that I'm from the UK so I automatically think of the time as GMT-5 which is not always the case. London time is currently GMT+1 and we're London-5 which is actually GMT-4.

BenAlabaster
A: 

I've tried with TimeZone.getDefault() on my phone and it worked :) (but on the emulator the hour was "slow" by 2 hours :S )

Jani