Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Does strftime apply timezone? I just tried but it seems localtime is not applied. I get "2011-03-15 16:54:24" instead of "2011-03-16 01:54:24" Commented Mar 15, 2011 at 17:11
  • 2
    datetime.now() is localtime. datetime.utcnow() returns the UTC compliant form. strftime just specifies the partial output from that datetime object. If you need a specific region timezone you should do something like, import pytz datetime.now(pytz.timezone('Africa/Casablanca')).strftime('%Y-%m-%d %H:%M:%S') Commented Apr 26, 2011 at 15:27