2018年7月31日 星期二

[ Python 常見問題 ] Formatting “yesterday's” date in python

Source From Here 
Question 
I need to find "yesterday's" date in this format MMDDYY in Python. So for instance, today's date would be represented like this: 111009 I can easily do this for today but I have trouble doing it automatically for "yesterday". 

How-To 
Check sample code below: 
>>> from datetime import date, timedelta
>>> yesterday = date.today() - timedelta(1)
>>> print yesterday.strftime('%m%d%y')
'110909'

>>> import time
>>> print("Time stamp={}".format(int(time.mktime(yesterday.timetuple()))))
Time stamp=1532966400

Supplement 
python时间,日期,时间戳处理

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...