ISO时间(ISO 8601)在Python中? [英] ISO Time (ISO 8601) in Python?

查看:153
本文介绍了ISO时间(ISO 8601)在Python中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件。在Python中,我想将其创建时间转换为 ISO时间(ISO 8601)字符串 ,同时保留在东部时区中创建的事实。



如何将文件的ctime转换为一个ISO时间字符串,表示东部时区(需要时考虑夏令时间)?

解决方案

本地到ISO-8601:

  import datetime 
datetime.datetime.now()。isoformat()

UTC到ISO-8601:

 code> import datetime 
datetime.datetime.utcnow()。isoformat()


I have a file. In Python, I would like to take its creation time, and convert it to an ISO time (ISO 8601) string while preserving the fact that it was created in the Eastern Time Zone.

How do I take the file's ctime and convert it to an ISO time string, that indicates the Eastern Time Zone (and takes into account daylight savings time, if necessary)?

解决方案

Local to ISO-8601:

import datetime
datetime.datetime.now().isoformat()

UTC to ISO-8601:

import datetime
datetime.datetime.utcnow().isoformat()

这篇关于ISO时间(ISO 8601)在Python中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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