Python scripts often need to automatically get the current time of the system and the time of the previous day, if in order to obtain the time of the previous day, simply take out the current system time (string type), converted to an integer minus 1, and then converted to a string type, is not feasible, the beginning of the month will appear 0 days, For example, December 1 will become 0 days, and reasonable practice should allow it to automatically push forward one day.
As follows:
1.python to get the current time there is a Times property
Import time
Time_now = Time.strftime ('%y%m%d ')
or Time_now = Time.strftime ("%y%m%d", Time.localtime ())//Gets the current time of year and month day
2. Get yesterday's time datetime
Import datetime
Now_time = Datetime.datetime.now ()
Yes_time = Now_time + Datetime.timedelta (days=-1)
or Yes_time=datetime.datetime.now ()-Datetime.timedelta (Days=1)
Yes_time_yes = yes_time. strftime ('%y%m%d ')//formatted output
This article is from the "one Gourd soy sauce" blog, please be sure to keep this source http://zhushenghang.blog.51cto.com/11105203/1825342
Python script--Gets the current time of the system and the day before