We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How do I print the time adjusted for Summer Time?

Richard Jebb
Richard Jebb asked
on
Medium Priority
397 Views
Last Modified: 2012-05-07
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

Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

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

you tell it to use GMT, not local time
To use local time, just remove that line
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> I did what you suggested but it made no difference.

that would be because your pc's timezone is not setup correctly
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.