我收到有关日期时间的错误消息

时间:2019-04-16 13:14:36

标签: python spyder

我正试图将带有小时的日期转换为日期。

请帮助我,这让我发疯。

这是我的脚本:

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')

这是错误消息:

ValueError: time data 'Date1' does not match format '%Y-%m-%d %H:%M:%S'

1 个答案:

答案 0 :(得分:3)

您应该使用变量Groups: +--------+-----+---------+----------+----------+ |Category|Value|Sequences|rangeStart|rangeEnd | +--------+-----+---------+----------+----------+ |1 |10 |0 |0 |4 | |1 |20 |0 |4 |5 | |1 |21 |0 |5 |8589934595| |1 |30 |0 |8589934595|8589934599| |1 |38 |0 |8589934599|null | +--------+-----+---------+----------+----------+ Units in groups: +--------+-----+----------+ |Category|Value|rangeStart| +--------+-----+----------+ |1 |11 |0 | |1 |13 |0 | |1 |16 |0 | |1 |22 |5 | |1 |25 |5 | |1 |27 |5 | |1 |29 |5 | |1 |32 |8589934595| |1 |34 |8589934595| |1 |35 |8589934595| +--------+-----+----------+ Result: +--------+-------+ |Category|summing| +--------+-------+ |1 |40 | |1 |103 | |1 |101 | +--------+-------+ 而不是字符串Date1

'Date1'