Latest web development tutorials

Pythonの昨日の日付を取得します。

ドキュメント・オブジェクト・リファレンス 例のpython3

昨日の日付を取得するにはdatetimeモジュールをインポートして、次のコード:

# Filename : test.py
# author by : www.w3big.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日です。

ドキュメント・オブジェクト・リファレンス 例のpython3