在 Python 2.5 中,如何以完整的 ISO 8601 格式打印当前时间戳 [英] In Python 2.5, how to print current timestamp in full ISO 8601 format

查看:31
本文介绍了在 Python 2.5 中,如何以完整的 ISO 8601 格式打印当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这一定在某处得到了回答,但我找不到.

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

如何以 ISO 8601 格式打印当前本地日期/时间,包括本地时区信息?

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

例如:2007-04-05T12:30-02:00

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?

请注意,我坚持使用 Python 2.5,这可能会降低某些选项的可用性.

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

推荐答案

通常这是通过 isoformat.它应该在 Python 2.5 中可用.

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

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

产生:

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

如果您的 tzinfo 中有正确的 UTC 偏移量,这也应该被渲染.

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

这篇关于在 Python 2.5 中,如何以完整的 ISO 8601 格式打印当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆