Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 676
  • Last Modified:

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";
0
TheVeee
Asked:
TheVeee
1 Solution
 
CEHJCommented:
What does

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

produce?
0
 
TheVeeeAuthor Commented:
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
0
 
allahabadCommented:
     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);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CEHJCommented:
You're not going to like this, but you might have to reinstall the JRE! I'll check...
0
 
TheVeeeAuthor Commented:
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).
0
 
vemulCommented:
>> 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?
0
 
CEHJCommented:
Hmm. It would be interesting to see what passing "user.timezone" to the following program produces:

public class Props {

  public static void main(String[] args){
    if(args.length > 0){
     for(int i = 0;i < args.length;i++){
      System.out.println(System.getProperty(args[0]));
     }
    }
    else {
      System.getProperties().list(System.out);
    }
  }
}
0
 
TheVeeeAuthor Commented:
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!!
0
 
TheVeeeAuthor Commented:
Thanks for the help... I think we both learned something on this.... Mainframe Java is tough!! Later!!
0
 
CEHJCommented:
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now