[英]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.