2017年10月9日 星期一

[ Python 常見問題 ] How to get the date N days ago in Python

Source From Here 
Below will use datetime & timedelta to get the date N days ago: 
>>> from datetime import datetime, timedelta 
>>> N = 2 // Calculate 2 days ago from now on 
>>> date_N_days_ago = datetime.now() - timedelta(days=N) 
>>> print datetime.now() 
2017-10-10 12:22:18.817720 
>>> print date_N_days_ago 
2017-10-08 12:22:07.384718


沒有留言:

張貼留言

[Linux 常見問題] What's the best way to send a signal to all members of a process group?

Source From  Here   Question   I want to  kill a whole process tree.  What is the best way to do this using any common scripting languages? ...