Link to home
Start Free TrialLog in
Avatar of fix2009
fix2009Flag for United States of America

asked on

Java Calendar Timezone issue

Appreciate your help in pin pointing the issue in following code. I am creating a Calendar object of a specific time zone, but it is still displaying the local time zone.
e.g.  I have currently US/Eastern DST

Date currentDate = new Date();
TimeZone timeZone = TimeZone.getTimeZone("Canada/Newfoundland")
Calendar calTime = Calendar.getInstance(timeZone);
calTime.setTime(baseDate);

I am expecting that calTime will print the current time in NewFoundLand timezone, but when I print the value of calTime.getTime() it is printing time in US Eastern.  I tried to check at line 3 and line 4, at both lines it is printing US Eastern time.

What changes needed to make so that it print NewfoundLand Time?   Thanks,

Avatar of Mick Barry
Mick Barry
Flag of Australia image

how do you display it, the wrapped date does *not* have any timezone associated with it
So if you are using DateFormat to display the date then you need to set the timezone for the DateFormat

Avatar of fix2009

ASKER

Ok. Let me simplify the question. How to display the NewfoundLand time being in a different timezone using Calendar or Date objects.
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
or just:

String formatted = df.format(currentDate);

SOLUTION
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