Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

local time and GMT time conversion not happening?

print(time.strftime('%a, %d %b %Y %H:%M:%S PST', time.localtime()))

^ the above prints the correct information, except for the 24 hour time. It displays it 10 hours ahead of where I am. I live in Oregon, USA so I am on Pacific Standard Time (PST). I thought that the , time.localtime() would change the time zone automatically when printing it.

1 Answer

Hi Austin,

I have a couple of follow-up questions to make sure I understand what you are expecting to see and what you are actually seeing.

  • You say your function prints the time 10 hours ahead of where you are. You also mention that you live in Oregon. Are you currently in Oregon?
  • Are you using the function on a local computer or on a remote system? Put another way, is the computer running Python in the same timezone as you?
  • Is Python running on a Windows or a Unix/Unixlike system?

Cheers

Alex