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

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

问题描述

t = e ['updated_pa​​rsed']
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

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

 2010年1月28日


解决方案

class有一个strftime方法。 strftime()行为 Python文档记录了它接受的不同格式。



对于这个具体的例子,它看起来像:

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


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"

解决方案

The datetime class has a method strftime. strftime() Behavior in 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 datetime转换为字符串,可读格式日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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