简体   繁体   中英

Python: Adding Time in a txt file

I have the below code where it is adds a header to my file. you can see in the header it adds; 'name', 'date' and 'time'.

what i am trying to attempted next is to add another line in the header called 'AddedTime'. this field needs to add 15 mins on top of the current time and output it out into the 'AddedTime' header.

Python code.

import datetime
print(datetime.datetime.now() + datetime.timedelta(minutes=15))

2019-03-21 12:57:50.418277

是的,使用datetime.timedelta非常简单,只需添加15分钟,您就可以使用strftime格式化日期时间输出。

addedTime  = (stamp + datetime.timedelta(minutes=15)).strftime('%H:%M:%S')

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