Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

British Summer Time/Daylight Savings

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi,

I'm currently displaying the time (GMT) but it's an hour out because of British Summer Time. Is there a method I can use to correct this automatically?

My code is as follows:

TimeZone timeZone = TimeZone.getDefault();
timeZone.setID("GMT");
calendar = Calendar.getInstance(timeZone);
timeString = timeFormatter.format(calendar.getTime());
timeLabel.setText(timeString.toString());
dateString = dateFormatter.format(calendar.getTime());
dateLabel.setText(dateString.toString());

Your help would be much appreciated :)
 
I don't know what platform you're on, but this has to be pulling the current time from the operating system. In other words, if your computers clock is reading the correct time, then your application should be picking it up.
 
I'm running from a PC: the time displayed in the task bar is an hour ahead because the 'Automatically adjust clock for daylight saving changes' check box has been checked. But my applet doesn't seem to recognize this!
 
I ran your code on my PC and it worked fine, except I didn't have the timeFormatter and dateFormatter objects. Odd thing, though ... I didn't get GMT like you'd expect, I got my time zone (Eastern US) properly adjusted for daylight savings time, the same as my system clock.

I tried TimeZone timeZone = TimeZone.getTimeZone("GMT"); but that didn't change the time either. Both operate as if I created the Calendar object with no time zone specified.

What happens when you do this?
 
Thanx for ur response!

When i do TimeZone.getDefault() it gives me GMT.
When i try to set it using the following line, I always get GMT as the output no matter what String i put in as a parameter:

TimeZone timeZone = TimeZone.getTimeZone("GMT");
or
TimeZone timeZone = TimeZone.getTimeZone("PST");
or
TimeZone timeZone = TimeZone.getTimeZone("CST");

Maybe it's not the function that sets it properly?!

Also, the British Summer Time thing happens automatically when i run my applet in Forte but not in JBuilder. Probably because I've got an early version of JBuilder (3.5)!!!

Anyway, if you need to add an hour you can just use:
calendar.roll(Calendar.YEAR, 1);

Thanx v.much for ur help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top