Link to home
Start Free TrialLog in
Avatar of Richard Jebb
Richard Jebb

asked on

How do I print the time adjusted for Summer Time?

After reading many forum posts and web pages on the correct way to display local time adjusted for daylight savings (summer time) here in the UK, I came up with the code below. This displays raw GMT however with no adjustment.

I am running Java 1.5.0_06 in Netbeans 6.5 on a PC running Windows XP with the timezone set for GMT and "automatically adjust for daylight saving changes" ticked. Is there anything else I need to define for the Java environment or is my code just wrong? If I tear any more hair out I'll soon be bald :-(
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzzz");
sf.setTimeZone(TimeZone.getTimeZone("GMT"));
String lvTimestamp = df.format(new Date());
System.out.println(lvTimestamp);

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

> sf.setTimeZone(TimeZone.getTimeZone("GMT"));

you tell it to use GMT, not local time
To use local time, just remove that line
ASKER CERTIFIED SOLUTION
Avatar of Richard Jebb
Richard Jebb

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
yes , am pretty sure the GMT timezones do not take daylightsaving into account (as they do not indicate the country), and are just straight GMT offsets
> I did what you suggested but it made no difference.

that would be because your pc's timezone is not setup correctly