[英]I'm getting an error message regarding datetime
I'm trying to turn a date with hours into just a date. 我正试着把几个小时的约会变成一个约会。
Please help me, this is driving me insane. 请帮助我,这让我疯了。
This is my script: 这是我的脚本:
from datetime import datetime
Date1= '2018-2-12 10:30:01'
d = datetime.strptime('Date1','%Y-%m-%d %H:%M:%S')
day_string = d.strftime('%Y-%m-%d')
and this is the error message: 这是错误消息:
ValueError: time data 'Date1' does not match format '%Y-%m-%d %H:%M:%S'
You should use the variable Date1
instead of the string 'Date1'
你应该使用变量
Date1
而不是字符串'Date1'
from datetime import datetime
Date1= '2018-2-12 10:30:01'
d = datetime.strptime(Date1,'%Y-%m-%d %H:%M:%S')
day_string = d.strftime('%Y-%m-%d')
print(day_string)
#2018-02-12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.