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:
You are not logged in, so your subscription status for this entry is unknown. You can login or register here.
