NO MORE CAREER
POLITICIANS!
Get Out Of Our House: Replacing congress with TRUE citizens!
Contact Doug!
Learn About Doug!
View Doug Boude's online resume
updated 11/18/2009

View Doug Boude's profile on LinkedIn
Link to me!

Follow Doug Boude on Twitter
Follow me!

Be Doug's friend on Facebook
Befriend me!
(I promise not to follow you home)
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...
Web Hosting

best web hosting - top web hosting sites, thetop10bestwebhosting.com

Czech your Page Rank!
Check Page Rank of any web site pages instantly:
This free page rank checking tool is powered by Page Rank Checker service
Surf's Up!
Visit Egosurf.org and massage YOUR web ego!
My Score: 9,001
Doug's Books

Read (and recommend)

  • Men are from Mars, Women are from Venus
  • The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collective Wisdom Shapes Business, Economies, Societies and Nations
  • Blink: The Power of Thinking Without Thinking
  • Head First Design Patterns
  • Transact-SQL Programming
  • What's So Amazing About Grace?
  • Just So Stories (Rudyard Kipling collection)

Reading

  • Prayer: Does it Make Any Difference?
  • Data Mining (Practical Machine Learning Tools and Techniques)
<< February, 2009 >>
SMTWTFS
1234567
891011121314
15161718192021
22232425262728
Search Blog

Recent Comments
Re: Railo 3.1 on Windows Server 2008 and IIS7 - Part 3 of 3 (by Jon at 8/27 2:04 PM)
Re: Hosts File Changes Not Acknowledged on Vista 64 (by Spacy at 8/24 3:46 PM)
Re: THE DAY CFUNITED DIED (by ComboFusion at 8/23 10:50 AM)
Re: My Grandpa (by Tasha at 8/10 4:29 PM)
Re: Just What IS a 'Service Layer', Anyway? (by dougboude at 8/02 10:10 AM)
Re: Just What IS a 'Service Layer', Anyway? (by Isaac at 8/02 2:25 AM)
Re: PayPal IPN Coldfusion CFC (by Soyestudiambre at 7/25 6:12 PM)
Re: PHP vs COLDFUSION (by Tony Garcia at 7/17 11:24 AM)
Re: PHP vs COLDFUSION (by dougboude at 7/14 8:45 AM)
Re: PHP vs COLDFUSION (by Lola LB at 7/14 5:51 AM)
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

17 December 2008
Getting a Complete List of Timezones from Java

I've been doing some research on i18n, locales, timezones, and all that jazz lately. Today I wanted to build a dropdown list of possible timezones, and came across a bit of Java code that I converted to CFSCRIPT. Thought I'd share it in case anybody else finds it useful. I will say that there are a LOT more timezones than I would have ever guessed (592 to be exact), and the results of my snippet probably aren't useful as-is to populate a dropdown; but, at least you do have a way to access what your CF server's JVM knows about, and you can filter it as you like.

Oh, I ran this code under CF8; not sure what it does under earlier versions.

The Code:

<!--- create list of valid time zones using java... --->

<cfscript>

tz = createobject("java","java.util.TimeZone");

aTZID = tz.getAvailableIDs();

today = now();

aTZs = arraynew(1);

for(i=1;i<=arraylen(aTZID);i=i+1){

tmptz = tz.getTimeZone(aTZID[i]);

stThisTZ = structnew();

stThisTZ.id = aTZID[i];

// Get the display name

stThisTZ.shortName = tmptz.getDisplayName(tmptz.inDaylightTime(today), tz.SHORT);

stThisTZ.longName = tmptz.getDisplayName(tmptz.inDaylightTime(today), tz.LONG);

stThisTZ.readableName = tmptz.getDisplayName();

 

// Get the number of hours from GMT

rawOffset = tmptz.getRawOffset();

stThisTZ.offset = rawOffset / (60*60*1000);

stThisTZ.offsetMinutes = abs(rawOffset / (60*1000)) % 60;

 

// Does the time zone have a daylight savings time period?

stThisTZ.hasDST = tmptz.useDaylightTime();

 

// Is the time zone currently in a daylight savings time?

stThisTZ.inDST = tmptz.inDaylightTime(today);

arrayAppend(aTZs,structcopy(stThisTZ));

}

</cfscript>

<cfdump var="#aTZs#">


screenshot of the output:
screenshot of output of timezones retrieved via java timezone object




Posted by dougboude at 7:16 AM | PRINT THIS POST! |Link | 3 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Getting a Complete List of Timezones from Java
Posted by PaulH on December 17, 2008 at 9:32 AM

Re: Getting a Complete List of Timezones from Java
nice article
Posted by bala on May 18, 2010 at 2:50 AM

Re: Getting a Complete List of Timezones from Java
@bala - thanks! :)
Posted by dougboude on May 18, 2010 at 10:14 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

10 plus 7 equals
Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!