• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

output TimeZone list as "America/Los_Angeles")

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we can get the display name like "Pacific Standard Time" by
TimeZone.getTimeZone("America/Los_Angeles").getDsiplayname()

but I need to get the list of all timezones as format "America/Los_Angeles" as that is the requried interface for other function, I haven't find java function to do that.

Any suggestions for the output timezone format of "America/Los_Angeles"?

Thanks,
[ November 17, 2006: Message edited by: Steve Jiang ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really sure if this is what you're asking for, but perhaps you might try:
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve: instead of getDisplayName(), try getID().
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply. I need to describe more for my issue. There is Jcombox with the list of timezone with format like "Ameria/New_York",

The original sample code could be like
m_timeZoneBox = new JComboBox(OraLocaleInfo.getCommonTimeZoneIDs());
m_timeZoneBox.setSelectedItem(TimeZone.getDefault().getID());
// notowrking as "PST8PDT" from TimeZone.getDefault().getID()); doesn't match string "Ameria/New_York" in the list of OraLocaleInfo.getCommonTimeZoneIDs


1. I need to put the default timezone based on JVM locale. Such as I am in New York, the selected item of jComobox list will be "America/new_Yrok"

2, I hope to localized the display to local language. If the locale of JVM is zh_CN for Chinese, the Jcombox list should be Chinese and the selected item should be in the position of "Asia/Shanghai"

Any comments are appreciated!
[ November 18, 2006: Message edited by: Steve Jiang ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Steve]: 1. I need to put the default timezone based on JVM locale. Such as I am in New York, the selected item of jComobox list will be "America/new_Yrok"

Well, it sounds like you are getting a default timezone based on the locale for your machine - it's but that locale hasn't been configured correctly. If the machine thinks it's in the Pacific Time Zone, when it's really in New York, something's misconfigured in the settings. The JVM does not have some special sensors to detect its own location through GPS, for example. Most laptops, for example, do not change their time zone settings automatically when you travel - you need to tell the laptop if you want a different time zone.

Aside from the configuration, I'm guessing you also won't like the format of the options. E.g. even if you were in LA, you'd want America/Los_Angeles rather than PST8PDT. Unfortunately, there are multiple ways of expressing the same time zone, as well as multiple time zones that arealmost identical but may have subtle differences. I don't know of any standard way to tell which ID name is "best" according to different users. What I would probably do is create a porperty file listing all the unacceptable time zone IDs and the alternate IDs they should be remapped to. E.g.

PST8PDT = America/Los_Angeles
US/Pacific = America/Los_Angeles

Unfortunately you will probalby have to build this list yourself, based on customer preferences. But you probably won't have to create listings for all time zones - just the ones your customers care about.

[Steve]: 2, I hope to localized the display to local language. If the locale of JVM is zh_CN for Chinese, the Jcombox list should be Chinese and the selected item should be in the position of "Asia/Shanghai"

The getDisplayName() method can accept a Locale to generate language-specific lables. But if you don't like the labels they choose, you'll need to create your own custom list of labels to override them with. I'd use a PropertiesResourceBundle to list whatever custom lables in different languages are desired. For any time zone / language combo not on the list, you can default to what getDisplayName() gives you, as it's presumeably better than nothing.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for comments.

For first issue,
m_timeZoneBox = new JComboBox(OraLocaleInfo.getCommonTimeZoneIDs()); //format like "America/New_YORK"
m_timeZoneBox.setSelectedItem(TimeZone.getDefault().getID());


I don't need it working as people travel. I think it is OK to set timezone list based on the locale setting of JVM (it will be better if it can be adjuested by timezone of computer), the TimeZone.getDefault().getID or getDisplayName can output the format as "PST" or ""Pacific Standard Time" and can't macth the format "America/Los_Angeles" which isoutput from OraLocaleInfo.getCommonTimeZoneIDs())


that is true, locale is not corresponding with timezone one by one, like English, chinese covers multiple timezones. I guess the first one from the string list is OK.

So as my first post, if we can find the way to output the timezone for differnt locale or timezone as format "America/Los_Angeles" it will be OK for me.


For the second issue for transaltion, I think Iit can be sloved by OraDisplayLocaleInfo as TimeZone.getDisplayName may get multiple "pacific Time" for serverl America west TimeZones.
like
America/Boise
America/Cambridge_Bay
America/Chihuahua
America/Dawson_Creek
America/Denver
.....
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not sure why "America/Los_Angeles" is used as input parameter for TimeZone.getTimeZone("America/Los_Angeles"), but no function to generate the output of ""America/Los_Angeles" by locale or timezone. The only format of TIMZONE is LONG for "Pacific Time Zone" or SHORT like "PST"
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you get your TimeZone from TimeZone.getTimeZone("America/Los_Angeles"), then getID() will return "America/Los_Angeles". Does on my machine, anyway - does it not on yours? But if you get your TimeZone from another source, it may return something else. Unfortunately, time zones can go by multiple names, and there is no single standard that Java implementations use. The only other solution I see is what I already suggested: provide a list of how you'd like to re-map time zone names, e.g. using a Properties file.
 
Steve Jiang
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your commnets. It is good to discuss more and get some idea. I think I can get it as follows.


getCommonTimeZones will provide the timezone list with ID format like "America/City" and it can be used to compare the current timezone.

Thanks again for your suggestions!
 
No, tomorrow we rule the world! With this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic