Link to home
Start Free TrialLog in
Avatar of bilgehanyildirim
bilgehanyildirim

asked on

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?

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia 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
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