Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Multi-time zone date/time value?

Reply
Thread Tools

Multi-time zone date/time value?

 
 
davout
Guest
Posts: n/a
 
      10-16-2003
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?


 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      10-16-2003
"davout" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      10-16-2003
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.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-16-2003
On Thu, 16 Oct 2003 07:27:59 +0100, "davout"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
prevent a postback when moving web parts from zone to zone. =?Utf-8?B?VmluY2UgVmFyYWxsbw==?= ASP .Net 0 02-08-2006 12:20 AM
Zone Alarm Firewall Attacks =?Utf-8?B?TWFkRG9n?= Wireless Networking 4 10-13-2005 06:55 AM
Zone Alarm D@annyBoy Wireless Networking 4 10-22-2004 01:54 PM
VPN Client Linksys Wireless, ADSL XP Error 800, Zone Alarm John Wireless Networking 0 08-19-2004 10:32 PM
Zone Alarm or Zone Alarm Pro? Jones Computer Information 5 02-20-2004 07:29 PM



Advertisments