如何生成特定格式的python时间戳? [英] How do I generate a python timestamp to a particular format?

查看:52
本文介绍了如何生成特定格式的python时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 python 中,如何生成这种特定格式的时间戳?

In python, how would I generate a timestamp to this specific format?

2010-03-20T10:33:22-07

2010-03-20T10:33:22-07

我搜索了高低,但找不到描述生成这种特定格式的正确术语.

I've searched high and low, but I couldn't find the correct term that describes generating this specific format.

推荐答案

看下面的例子:

import datetime 
now = datetime.datetime.now()
now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))

这可能会导致以下结果:'2017-09-20T11:52:32-98'

This could result in the following: '2017-09-20T11:52:32-98'

这篇关于如何生成特定格式的python时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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