wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Date/Time Retrieval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date/Time Retrieval" Watch "Date/Time Retrieval" New topic
Author

Date/Time Retrieval

Richard Davis
Greenhorn

Joined: Jul 05, 2004
Posts: 12
Hi,

Not sure if this is the right place to ask this, but I thought I'd try! When running on the AS400, can anyone tell me where the cal.get function picks up the date/time from? I have a suspicion that it is picking it up wrongly, but I'm not sure...

Cheers,

Richard
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
It will get the date/time of the system itself... It won't get from the server machine that it is connecting...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Richard Davis
Greenhorn

Joined: Jul 05, 2004
Posts: 12
It isn't picking up the standard AS400 system date/time, nor the job date/time. It is out by an hour, though, so I think it may be to do with BST - how can I see the system defaults for the rules that govern the handling of this? (In case you haven't guessed my java knowledge is pretty much zero!)

If it's any help, the code is:


Calendar cal = new GregorianCalendar();

BigDecimal logDate = new BigDecimal(cal.get(Calendar.YEAR)*10000
+ (cal.get(Calendar.MONTH)+1)*100
+ cal.get(Calendar.DAY_OF_MONTH));

BigDecimal logTime = new BigDecimal(cal.get(Calendar.HOUR_OF_DAY)*10000
+ cal.get(Calendar.MINUTE)*100
+ cal.get(Calendar.SECOND));
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Hi, I'm not exactly sure what you wishes to do here. But it seems to me that you're trying to obtain a current system timestamp for logging purposes. Not very sure why you're using BigDecimal here though.

Anyway, here's my codes for getting the current system timestamp in a formatted pattern.



Hope this helps.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Richard Davis
Greenhorn

Joined: Jul 05, 2004
Posts: 12
Hi,

Tried the code suggested, but am getting the same symptoms. When running on my PC I get the correct date/time, but when running on the AS400 I get the time 1 hour ago...

Grrr


Any thoughts would be much appreciated!


Richard
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Looking at the source for JDK 1.4, TimeZone uses the system properties "user.timezone", "user.country", and "java.home" in the getDefault() static method. It seems like getDefault() relies on a number of native implementations to do its work so the AS400 just might be doing things a bit differently from the PC when it comes to the default TimeZone and Locale.

Try running the code below to see what kind of values you get and what differences there are between PC and AS400 environments. There might be a simpler, more straightforward way but you could try creating a SimpleTimeZone and passing that to the GregorianCalendar constructor to make sure you have the timezone you need. See the JavaDoc for GregorianCalendar for an example.



Junilu - [How to Ask Questions] [How to Answer Questions]
 
wood burning stoves
 
subject: Date/Time Retrieval
 
Similar Threads
Getting back after a gap
Date comparison
Help in using DateFormat
OS X Lion is out of the cage
PreparedStatement.setDate() is cutting the time part