【python 获取日期】python自定义函数获取昨天和今天的日期

import datetime


def getToday():
    """
    :return: 获取今天日期
    """
    today = datetime.date.today()
    # 日期转字符串
    record_date=today.strftime('%Y-%m-%d')
    return record_date


def getYesterday():
    """
    :return: 获取昨天日期
    """
    today = datetime.date.today()
    oneday=datetime.timedelta(days=1)
    yesterday=today-oneday
    # 日期转字符串
    partition_date=yesterday.strftime('%Y-%m-%d')
    return partition_date



today=getToday()
print(today)

partition_date=getYesterday()

print(partition_date)
2018-09-17
2018-09-16

Process finished with exit code 0
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页