fix2009
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("Cana da/Newfoun dland")
Calendar calTime = Calendar.getInstance(timeZ one);
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,
e.g. I have currently US/Eastern DST
Date currentDate = new Date();
TimeZone timeZone = TimeZone.getTimeZone("Cana
Calendar calTime = Calendar.getInstance(timeZ
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,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or just:
String formatted = df.format(currentDate);
String formatted = df.format(currentDate);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So if you are using DateFormat to display the date then you need to set the timezone for the DateFormat