I want to print the time in one of my program's but the time is an hour wrong, this is what i'm using.

from time import gmtime, strftime
strftime("%Y-%m-%d %H:%M:%S", gmtime())

it gives '2013-05-06 09:06:25 ' where the current time is 10:06:25.

Recommended Answers

All 3 Replies

Your "current time" might be misunderstood.

The gmtime function returns the local representation of UTC in seconds.
If your "current time" is local time, and are in a timezone UTC+1 geographicaly or in time, then the output is correct.

Where are you, and when did you run this?
If you are here end this time: "USA, Canada clocks on Daylight Saving Time until Sunday 3 November 2013 at 2am local time", then ok.

See:
http://wwp.greenwichmeantime.com/time-zone/gmt-plus-1/

Yes im on UCT+1 so how would i change the code for that?

Simple: use the function localtime() instead of gmtime().

commented: Worked great, thanks :) +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.