Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get country name for a particluar TimeZone object??

 
sujay bawaskar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need to develope a website which shows the client time and the client timezone. I get the Locale of client and time zone offset from javascript but I am not able to obtain exact time zone of client as an offset has multiple time zones. Please help me on this.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your exact question? Your subject line is not related to your actual post.

The answer to the question in your subject line is simple: you can't. The reason is quite clear: a time zone does not have a specific country; many time zones are used in multiple countries. For instance, CET spans half of Europe.

About your second question: you say you have the offset, right? You can then create an instance of SimpleTimeZone using that offset.
 
sujay bawaskar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the problem only, one Time zone offset spans over multiple timezone, hence i am not able to get exact timezone for my client side. If i get country for that timezone then i can figure it out.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you can't. Two good examples: the United States and Russia both span multiple time zones. In the end, there is a many-to-many relation between countries and time zones: a time zone can span multiple countries, and a country can span multiple time zones. The only way to get the correct time zone is to know the exact location; that is, the longitude and latitude. Some time zones do not run in parallel with meridians, so only the longitude is not enough.
 
sujay bawaskar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic