简体   繁体   English

如何在 Python 中将 yyyy-mm-dd (2018-08-09) 转换为 Aug09?

[英]How do I convert yyyy-mm-dd (2018-08-09) to Aug09 in Python?

I'm plotting a graph with anaconda and it's taking a start_dt = x1[0] and end_dt = x1[29].我正在用 anaconda 绘制图形,它采用 start_dt = x1[0] 和 end_dt = x1[29]。 There are 30 values on the x axis. x 轴上有 30 个值。 Right now, the date getting picked is already in Aug09 form.现在,选择的日期已经是 Aug09 的形式。 But I want to switch to another file where the dates are in yyyy-mm-dd form.但我想切换到另一个文件,其中日期为 yyyy-mm-dd 形式。 How do I change the format of the date when it's getting passed to the state_dt and end_dt?当日期传递给 state_dt 和 end_dt 时,如何更改日期的格式?

plt.suptitle(heading + start_dt + '-' + end_dt, size=26, fontweight='bold', va='top')
date_str = '2018-08-09'
d = datetime.strptime(date_str, '%Y-%m-%d')
print(d.strftime('%b%d')

See Also the python datetime reference另请参见python 日期时间参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 09-Jan-2019 格式的 excel 中解析日期并使用 python 将其转换为 yyyy-mm-dd 格式 - how can I parse a date from excel in 09-Jan-2019 format and convert it into yyyy-mm-dd format using python 使用python,如何将csv文件中存储为m(m)/ dd / yyyy的日期转换为yyyy-mm-dd以在sqlite中使用? - Using python, how do I convert dates that are stored as m(m)/dd/yyyy in a csv file to yyyy-mm-dd for use in sqlite? 在python中将yyyy-dd-mm转换为yyyy-mm-dd - convert yyyy-dd-mm to yyyy-mm-dd in python 如何在 Pandas 中将 'Month(String) YYYY' 转换为 'YYYY-MM-DD'? - How do I convert 'Month(String) YYYY' to 'YYYY-MM-DD' in Pandas? 在 Python 中将 YYYY-MM-DD 转换为 DD-MMM-YYYY - Convert YYYY-MM-DD to DD-MMM-YYYY in Python 在2014年1月4日给出时如何将mm / dd / yyyy格式转换为python 3.0中的yyyy-mm-dd - How to convert from mm/dd/yyyy format to yyyy-mm-dd in python 3.0 when given 1/4/2014 如何在 Python 中将日期格式 (YYYY-MM-DD) 转换为 (YYYY,MM,DD) - How to convert a date format (YYYY-MM-DD) to (YYYY,MM,DD) in Python 如何在 python 中将 (2018-09-05T09:00:06.540486Z) 转换为 (2018-09-05)? - How To Convert (2018-09-05T09:00:06.540486Z) Into (2018-09-05) In python? 在Python中将yyyy-mm-dd转换为yyyy-ww - Convert yyyy-mm-dd to yyyy-ww in Python Python`YYYY-MM-DD` - Python `YYYY-MM-DD`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM