原创

【python 日期加减】python日期加减几分钟

from datetime import datetime, timedelta


#把datetime转成字符串
def datetime_toString(dt):
    return dt.strftime("%Y-%m-%d %H:%M:%S")


#把字符串转成datetime
def string_toDatetime(string):
    return datetime.strptime(string, "%Y-%m-%d %H:%M:%S")

# 加一分钟或5分钟
def datetime_add(dt_string,minutes):
    delta = timedelta(minutes=minutes)
    n_days = string_toDatetime(dt_string) + delta
    return n_days
正文到此结束