简体   繁体   中英

Python converting timestamp issue

Im trying to covert the string value with timestamp as well as timedelta.

Code:

from datetime import datetime, timedelta

frmt = '%Y-%m-%d %H:%M:%S'
start = '2020-12-01 10:10:00'
stime = datetime.strptime(start, frmt)
print(stime)
etime =  stime.timedelta(days=1)
print(stime)
print(etime)

but its giving the following error.

2020-12-01 10:10:00
Traceback (most recent call last):
  File "<string>", line 9, in <module>
AttributeError: 'datetime.datetime' object has no attribute 'timedelta'

Here is the solution that worked from the comments:

from datetime import datetime, timedelta

frmt = '%Y-%m-%d %H:%M:%S'
start = '2020-12-01 10:10:00'

stime = datetime.strptime(start, frmt)
etime =  stime + timedelta(days=1)

print('stime', stime, 'etime', etime)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM