In Python 2.5, how to print current timestamp in f

2019-08-27 20:43发布

This question already has an answer here:

I'm sure this must be answered somewhere, but I can't find it.

How do I print the current local date/time in ISO 8601 format, including the local timezone info?

eg: 2007-04-05T12:30-02:00

In particular (and this is the difference to the other question) - how do I get the local timezone?

Note, I'm stuck at Python 2.5, which may reduce some availability of options.

标签: python time
1条回答
做个烂人
2楼-- · 2019-08-27 21:22

Usually this is done via isoformat. It should be available in Python 2.5.

from datetime import datetime
dt = datetime.now()
dt.isoformat("T")

which yields:

'2014-07-03T17:36:23.622683'

If you have correct UTC offsets in your tzinfo this should be rendered aswell.

查看更多
登录 后发表回答