File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Date/Time Retrieval

Richard Davis

Joined: Jul 05, 2004
Posts: 12

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...


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
Richard Davis

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

Joined: Jul 05, 2004
Posts: 12

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...


Any thoughts would be much appreciated!

Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Looking at the source for JDK 1.4, TimeZone uses the system properties "user.timezone", "", 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]
I agree. Here's the link:
subject: Date/Time Retrieval
It's not a secret anymore!