Multi-time zone date/time value?

Discussion in 'Java' started by davout, Oct 16, 2003.

  1. davout

    davout Guest

    If I have a class that wishes to store a date/time value that is valid
    across multiple time zones what data members should I add?
     
    davout, Oct 16, 2003
    #1
    1. Advertising

  2. "davout" <> writes:
    > If I have a class that wishes to store a date/time value that is valid
    > across multiple time zones what data members should I add?


    A simple long. And get the data from java.util.Date.getTime(). If you
    don't have messed up you computer clock, you get GMT (UTC) based
    date/time data that does not depend on timezones or DST.

    /Thomas
     
    Thomas Weidenfeller, Oct 16, 2003
    #2
    1. Advertising

  3. davout

    Sudsy Guest

    davout wrote:
    > If I have a class that wishes to store a date/time value that is valid
    > across multiple time zones what data members should I add?
    >
    >


    One of the things Java "inherited" from Unix was the internal
    representation of time. It's stored relative to UTC (nee GMT)
    and so is inherently valid world-wide. All you do is display
    or print it in the local format when needed. Try this simple
    Java program:

    import java.text.*;
    import java.util.*;

    public class x {

    public static void main( String args[] ) {
    SimpleDateFormat df = new SimpleDateFormat();
    Date timeNow = new Date();

    df.setTimeZone( TimeZone.getTimeZone( "PST" ) );
    System.out.println( df.format( timeNow ) );
    df.setTimeZone( TimeZone.getTimeZone( "EST" ) );
    System.out.println( df.format( timeNow ) );
    df.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
    System.out.println( df.format( timeNow ) );
    }
    }

    On my machine it generates output like this:

    10/16/03 6:51 AM
    10/16/03 9:51 AM
    10/16/03 1:51 PM

    The underlying Date object (timeNow) hasn't change, merely
    the rendering according to the TimeZone.
     
    Sudsy, Oct 16, 2003
    #3
  4. davout

    Roedy Green Guest

    On Thu, 16 Oct 2003 07:27:59 +0100, "davout"
    <> wrote or quoted :

    >If I have a class that wishes to store a date/time value that is valid
    >across multiple time zones what data members should I add?


    Date or the extracted long are in milliseconds since 1970 in GMT. The
    are thus time-zone independent.

    See http://mindprod.com/jgloss/calendar.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Oct 16, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryu

    Time Zone in Windows Time

    Ryu, Sep 15, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    18,298
    madamut
    Feb 11, 2009
  2. =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=

    prevent a postback when moving web parts from zone to zone.

    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=, Feb 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    587
    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=
    Feb 8, 2006
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,279
    Michael Borgwardt
    May 30, 2004
  4. Replies:
    8
    Views:
    786
    Boris
    May 1, 2007
  5. Alexander Vasilevsky
    Replies:
    5
    Views:
    394
    Duy Lam
    Dec 11, 2007
Loading...

Share This Page