Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:59:33+00:00 2026-05-28T19:59:33+00:00

We store our dates are stored in milliseconds since the epoch and the Olson

  • 0

We store our dates are stored in milliseconds since the epoch and the Olson time zone ID for the objects we want to display time related data about.

How can I convert the Olson TZID to a TimeZoneConstant to create a TimeZone and use DateTimeFormat?

// values from database
String tzid = "America/Vancouver";
long date = 1310771967000L;


final TimeZoneConstants tzc = GWT.create(TimeZoneConstants.class);
String tzInfoJSON = MAGIC_FUNCTION(tzid, tzc);
TimeZone tz = TimeZone.createTimeZone(TimeZoneInfo.buildTimeZoneData(tzInfoJSON));
String toDisplay = DateTimeFormat.getFormat("y/M/d h:m:s a v").format(new Date(date), tz); 

Does that MAGIC_FUNCTION exist? Or is there another way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:59:34+00:00Added an answer on May 28, 2026 at 7:59 pm

    Doing a GWT.create on the TimeZoneConstants class is bad game according to the GWT Javadoc [1]. So what I did was create a class on the server-side that parses /com/google/gwt/i18n/client/constants/TimeZoneConstants.properties and builds a cache of all the JSON objects for each time zone (indexed by their Olson TZID).

    My site is running on jboss, so I copied TimeZoneConstants.properties into my site’s war/WEB-INF/lib directory (probably didn’t need to copy it there since the GWT jars are already there). Then I have a singleton class that does the parsing when constructed:

    InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROPERTIES_FILE);
    InputStreamReader isr = new InputStreamReader(inStream);
    BufferedReader br = new BufferedReader(isr); 
    for (String s; (s = br.readLine()) != null;) { 
      // using a regex to grab the id to use as a key to the hashmap
      // a full json parser here would be overkill
      Pattern pattern = Pattern.compile("^[A-Za-z]+ = (.*\"id\": \"([A-Za-z_/]+)\".*)$");
      Matcher matcher = pattern.matcher(s);     
      if (matcher.matches()) {
        String id = matcher.group(2);
        String json = matcher.group(1);
    
        if (!jsonMap.containsKey(id)) {
          jsonMap.put(id, json);
        }
      }
    } 
    br.close();
    isr.close();
    inStream.close();
    

    Finally I make an RPC call to get the TimeZoneInfoJSON to the client (assuming the server knows which TimeZoneID I’m interested in):

    getTimeZone(new PortalAsyncCallback<String>() {
      public void onSuccess(String tzJson) {
        timeZone = TimeZone.createTimeZone(TimeZoneInfo.buildTimeZoneData(tzJson));
      }
    });
    

    Not the most elegant solution but it has given me a way to display dates and times for a specific time zone over DST transitions.

    [1] http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/i18n/client/constants/TimeZoneConstants.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We store all our dates SQL Server 2008 database in UTC time in DateTime
All of our date/time data in our database is stored in UTC time. I'm
Our software has data to store, so it also install MYSQL, a root user
Our DBA requires us to return all tabular data from stored procedures in a
I am working on a C# application and want to display dates so they
I have 100000 Ids to store into our DataBase. Id is in string format.each
Our Magento store uses the Website Payments Pro payment gateway through PayPal. For the
Our business currently has an online store and recently we've been offering free specials
i wanted to know where we should store the db in our project and
In one page of our site, I have this code: $_SESSION['returnURL'] = /store/checkout/onepage; and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.