Python 获取昨天日期

Python 3 教程 · 2019-02-12 15:41:53

以下代码通过导入 datetime 模块来获取昨天的日期:

# Filename : test.py # author by : www.codercto.com # 引入 datetime 模块 import datetime def getYesterday(): today=datetime.date.today() oneday=datetime.timedelta(days=1) yesterday=today-oneday return yesterday # 输出 print(getYesterday())

执行以上代码输出结果为:

2015-06-10

以上实例输出的意思为昨天的日期是 2015 年 6 月 10 日。

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Speed Up Your Site

Speed Up Your Site

Andrew B. King / New Riders Press / 2003-01-14 / USD 39.99

There's a time bomb on the web: user patience. It starts ticking each time someone opens one of your pages. You only have a few seconds to get compelling content onto the screen. Fail, and you can kis......一起来看看 《Speed Up Your Site》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具