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

x
?
Solved

Java Calendar returning wrong time

Posted on 2009-04-22
3
Medium Priority
?
356 Views
Last Modified: 2012-05-06
I have an app running on two Centos machine. The app running on both servers is identical
when I run the following code, on one machine I get correct time but on the second server, I get 5 hrs early time.

Corret : 22/04/2009 10:22:23
Wrong : 22/04/2009 05:22:23

linux date command and locale command outputs for both servers are same. Can someone tell me where else I need to check?

Thanks
Bill
Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(cal.getTime());

Open in new window

0
Comment
Question by:bilgehanyildirim
  • 3
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 24202670
sounds like the default tz is different on the two boxes, check that

0
 
LVL 92

Expert Comment

by:objects
ID: 24202686
and check the TZ env var

echo $TZ

0
 
LVL 92

Expert Comment

by:objects
ID: 24202710
>         SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

and change that to

        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z zzz");

that way we can see the tz being used

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question