🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
4 messages
4 total messages Started by jam Fri, 21 May 1999 00:00
read local date?
#1137
Author: jam
Date: Fri, 21 May 1999 00:00
11 lines
744 bytes
Hi all.

Can anyone pls tell me how to read local date/time into variables?
I used the Calendar  class,  and can get hour/month/day of month etc
into serparate variables, however, when I get the hour of day, the hour
is wrong, like now, it is 10pm, but it said it is 8am..

Anyone?

Thanks
James.
Re: read local date?
#1138
Author: Fred Ghelem
Date: Sat, 22 May 1999 00:00
1 lines
719 bytes
You have to change the Locale
Re: read local date?
#1139
Author: jam
Date: Sat, 22 May 1999 00:00
28 lines
1310 bytes
Fred Ghelem wrote:

> You have to change the Locale

The problem is how to set it to be the same for the place where the
program is run?  how to get the locale  to be the same as the computer
which the program is running on??
What I have so far....

    TimeZone tz = TimeZone.getDefault();
    Calendar rightNow = Calendar.getInstance(tz);
    System.out.println("ID:" + tz.getID()+"  HOUR_OF_DAY: "
                                            + rightNow.get(
Calendar.HOUR_OF_DAY ));

and i get this under jdk1.1.7 in linux

ID:EST  HOUR_OF_DAY: 17

but if I get the REAL time/date of my linux box by typing 'date' in
console...i get
Sat May 22 07:13:52 EST 1999

Which is a BIG difference...the timezone is correct, but hour is still
not. :(

Any idea?
James.
Re: read local date?
#1142
Author: Dion Gillard
Date: Sun, 23 May 1999 00:00
33 lines
1719 bytes
[This followup was posted to aus.computers.java and a copy was sent to 
the cited author.]

In article <3745CCE4.D778E9D1@ihug.com.au>, jho@ihug.com.au says...
|  Fred Ghelem wrote:
|  
|  > You have to change the Locale
|  
|  The problem is how to set it to be the same for the place where the
|  program is run?  how to get the locale  to be the same as the computer
|  which the program is running on??
|  What I have so far....
|  
|      TimeZone tz = TimeZone.getDefault();
|      Calendar rightNow = Calendar.getInstance(tz);
|      System.out.println("ID:" + tz.getID()+"  HOUR_OF_DAY: "
|                                              + rightNow.get(
|  Calendar.HOUR_OF_DAY ));
|  
|  and i get this under jdk1.1.7 in linux
|  
|  ID:EST  HOUR_OF_DAY: 17
|  
|  but if I get the REAL time/date of my linux box by typing 'date' in
|  console...i get
|  Sat May 22 07:13:52 EST 1999
|  
|  Which is a BIG difference...the timezone is correct, but hour is still
|  not. :(

Did you try using Locale.getDefault() for your timezone etc?

dIon
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads