Link to home
Start Free TrialLog in
Avatar of TheVeee
TheVeeeFlag for United States of America

asked on

6 hours off from current timestamp

Im using the following code and my time is off 6 hours from what the system clock is. Im on central time if that matters.  My question is, how do I get this to show the exact time it is currently vice 6 hours ahead????

Calendar cal = new GregorianCalendar();
SimpleDateFormat formatter1 = new SimpleDateFormat("yy_MM_dd_HH_mm_ss");
        String inputDate2 = formatter1.format(cal.getTime()) + "_000000";
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What does

System.out.println(cal.getTime());

produce?
Avatar of TheVeee

ASKER

Sorry, had to deploy this to mainframe...

Time was
cal.getTime(): Fri Feb 28 16:15:36 GMT 2003
and the actual time was 10:15 AM Central Standard Time
Avatar of allahabad
allahabad

     SimpleDateFormat formatter1 = new SimpleDateFormat("yy_MM_dd_HH_mm_ss");
      Date currentDate = new Date();
      long time = currentDate.getTime()+6*60*60*1000; // add 6 hours in millisecond
      currentDate.setTime(time);
      String formatedDate = formatter1.format(currentDate);
You're not going to like this, but you might have to reinstall the JRE! I'll check...
Avatar of TheVeee

ASKER

CEHJ,

My Websphere System guy thinks this is a global setting so it will read the uses default Profile.  The user profile usually has a TZ environment variable which tells the Timezone, subtract 6 hours and so forth.  He thinks that when the IBM Websphere is starting it isnt using that standard profile so he needs to see how IBM has compensated for this problem in the UNIX environment. I actually running this on a OS/390 Mainframe System (Websphere).
>> cal.getTime(): Fri Feb 28 16:15:36 GMT 2003

as it says you are showing the GMT time. To convert it to different timezone, maybe CST, try changing the timezone and verifying it. Does the machine on which you program runs display time in GMT format?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheVeee

ASKER

CEHJ,

Thanks for the input.  Turns out called IBM and on the Mainframe System for each server there is a setting you have to put in the JVM.Properties file for that particuliar server.  The setting must be set to user.timezone=CST or user.timezone = CDT.  Then recycle server and WALA... it worked... By the way thanks for your time and I will give you the 50 points for researching...Thanks again, like usual!!
Avatar of TheVeee

ASKER

Thanks for the help... I think we both learned something on this.... Mainframe Java is tough!! Later!!
:-)