Java Calendar returning wrong time

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?

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

Open in new window

Who is Participating?
sounds like the default tz is different on the two boxes, check that

and check the TZ env var

echo $TZ

>         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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.