Python has two modules, time and DateTime, which, of course, need to be import first when used.
Get system Current Time Time.localtime (Time.time ())
The formatted output of the time can be used with the strftime, called Time.strftime ()
Example for Current_time=time.strftime ('%y-%m-%d ', Time.localtime (Time.time ()))
The time format for the output is 2015-02-11, and this output is a string type of data
and datatime. Get Time Datetme.datetime.now ()
The call to adjust time in DateTime is Datetime.timedelta ()
For example, get yesterday's date for Datetime.datetime.now () +datetime.timedelta (days=-1)
You want to format the output as yesterday= (Datetime.datetime.now () +datetime.timedelta (Days=-1)). Strftime ('%y-%m-%d ')
The output time format is also 2015-02-10, and this output is also a string type of data.
This article is from the "Learning discussion" blog, so be sure to keep this source http://ltm250.blog.51cto.com/4695970/1613710
Get system time and format output under Python