如何将 python 日期时间转换为字符串,具有可读格式的日期? [英] How do I turn a python datetime into a string, with readable format date?

查看:30
本文介绍了如何将 python 日期时间转换为字符串,具有可读格式的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003

如何将其转换为字符串?:

How do I turn that into a string?:

"January 28, 2010"

推荐答案

datetime 类有一个方法 strftime.Python 文档记录了它接受的不同格式:

The datetime class has a method strftime. The Python docs documents the different formats it accepts:

对于这个特定的例子,它看起来像:

For this specific example, it would look something like:

my_datetime.strftime("%B %d, %Y")

这篇关于如何将 python 日期时间转换为字符串,具有可读格式的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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