aspose file tools*
The moose likes Features new in Java 8 and the fly likes best way to locate a time zone in Europe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 8
Bookmark "best way to locate a time zone in Europe?" Watch "best way to locate a time zone in Europe?" New topic
Author

best way to locate a time zone in Europe?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

I was trying to write a program that involves the time zone in Germany. (It's an exercise in Cay Horstmann's book). Since I didn't know the time zone identifier for Germany, I wrote a line of code to spit out all the European time zones:



Then I picked Berlin because I know it is in Germany. This doesn't feel like an efficient way of finding out this information. Is there a "standard" list/map of time zones people in Europe use? For example, in the US.

Granted I don't do this often and my approach worked. But it did get me curious.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

It's not really an issue over here, because most countries here are only in one time zone, and we rarely need to deal with time zones of other countries.

If I do need to find out a specific time zone, I just hit Google. The first few site provide plenty of information, and Google Images shows maps of time zones.

Is there a reason you need Europe/Berlin over CEST?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Stephan van Hulst wrote:It's not really an issue over here, because most countries here are only in one time zone, and we rarely need to deal with time zones of other countries.

Funny. That's the same reason I don't know. (As someone in the US, I rarely deal with time zones in other countries.)

Stephan van Hulst wrote:Is there a reason you need Europe/Berlin over CEST?

Because I don't know any better? It doesn't matter for my toy program. I suspect I do want CEST (central european standard time) because my question was about more general time zones. And because I can't find CEST in the list of Java time zones.

1) There's nothing with CEST in the name.

2) Here's what the choices are for names containing Central (clearly not the answer


3) And here's what the choices are for names containing Europe:
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

Okay, well after doing a little bit of research, you probably want your program to work properly all year round, so CEST won't do (CEST stands for Central European Summer Time, which is only used during the summer). For the same reason, neither will CET because in most European countries it's only used during the winter.

Instead, you can use whatever time zone you want that obeys Daylight Saving Time. In the Netherlands, we usually use Europe/Amsterdam or Europe/Paris and I've even seen Europe/Madrid. Europe/Berlin or Europe/Hessen would also work.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

Hmm the Java 8 time package is quite interesting. Here's a method that will print the local time for a given Clock. You can imagine a Clock being like a physical clock on a wall somewhere, using that time zone.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Yes. That requires you to know which time zone you want though!
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Yeah, the problem of identifying your correct time zone from among the various candidate ids - that hasn't really changed since Java's inception. It's really all from the tz database - I like using the list here. The [continent]/[city] IDs (like America/Los_Angeles) seem to offer the most comprehensive list of options, but can be hard to navigate for folks not very familiar with the region in question. the [country]/[specifier] IDs (like US/Pacific) are much more readable, at least for the US - but Europe doesn't seem to have an equivalent. Too bad.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

Interestingly, when I print the time zone that my system uses, it says Europe/Berlin. Windows lumps Amsterdam, Berlin, Bern, Rome, Stockholm and Vienna together. What makes it more interesting is that Windows also lumps Brussels, Copenhagen, Madrid and Paris together in a separate category.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Stephan,
That would be more interesting if I had a map in front of me . I do recognize the countries they are from, but not the time zones they are in. [teasing - I did look at a map]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Stephan van Hulst wrote: . . . Brussels, Copenhagen, Madrid and Paris together in a separate category.
What about Lisbon? At the risk of being moved to MD, why does Portugal which is far west of Britain use a time zone one hour ahead of us?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

They don't. They're in the same time-zone: WET in the winter and WEST in the summer. France and Spain however should also be in WET/WEST, except they're problably in CET/CEST to adapt to the rest of mainland Europe.

If you try to change the time zone of your Windows clock, you'll notice that Lisbon and London are in the same option.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Mike Simmons wrote:Yeah, the problem of identifying your correct time zone from among the various candidate ids - that hasn't really changed since Java's inception. It's really all from the tz database - I like using the list here. The [continent]/[city] IDs (like America/Los_Angeles) seem to offer the most comprehensive list of options, but can be hard to navigate for folks not very familiar with the region in question. the [country]/[specifier] IDs (like US/Pacific) are much more readable, at least for the US - but Europe doesn't seem to have an equivalent. Too bad.

new GregorianCalendar(locale).getTimeZone()?


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Thank you. I was obviously mistaken there.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Dieter Quickfend wrote:
Mike Simmons wrote:Yeah, the problem of identifying your correct time zone from among the various candidate ids - that hasn't really changed since Java's inception. It's really all from the tz database - I like using the list here. The [continent]/[city] IDs (like America/Los_Angeles) seem to offer the most comprehensive list of options, but can be hard to navigate for folks not very familiar with the region in question. the [country]/[specifier] IDs (like US/Pacific) are much more readable, at least for the US - but Europe doesn't seem to have an equivalent. Too bad.

new GregorianCalendar(locale).getTimeZone()?

Nope. This still uses the default time zone, ignoring locale. If I do this with Locale.CHINA, I get the America/Denver time zone.

Also, GregorianCalendar is evil, and if we're using Java 8, we wish to avoid it at any cost.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Mike Simmons wrote:Also, GregorianCalendar is evil, and if we're using Java 8, we wish to avoid it at any cost.

Definitely! I'm really impressed with the Java 8 time classes.

All: Interesting discussion about time zones.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best way to locate a time zone in Europe?