One: String and time series conversions
Time.strptime (): string = time sort
Time.strftime (): Time series = string
Import time
Start= "2017-01-01"
End= "2017-8-12"
Starttime=time.strptime (Start, "%y-%m-%d")
Endtime=time.strftime (end, "%y-%m-%d")
Print (StartTime);p rint (endTime)
_start=time.strftime ("%y%m%d-%h:%m:%s", StartTime)
_end=time.strftime ('%y%m%d-%h:%m:%s ', endTime)
Print (_start)
Print (_end)
Two: Time stamp
Time.mktime (t): convert time to timestamp
Time.localtime (s): convert timestamps to TIME
Startstamp=time.mktime (startTime) #time = time stamp
Endstamp=time.mktime (EndTime)
Print (Startstamp)
Print (Endstamp)
_starttime=time.localtime (start) #时间戳 =>time
Print (_starttime)
Three: Date arithmetic
Note: The timestamp starts in 1970, in seconds, so the calculation can be implemented according to the seconds
For example: Calculate the number of days between StartTime and Endtime:
Print (int ((Endstamp-startstamp)/(24*60*60)))
Four: Format summary
%a English Week abbreviation
%A full writing of English week
%b English month abbreviation
%B full write of English month
%c Displays the local date time
%d date. 1-31
%H hours. 0-23
%I Hours. 0-12
%m month. 01-12
%M points. 1-59
%j Days of the year
%w shows today is the day of the week
%W the first few weeks
%x Day Date
Time of day in%x Local
%y year 00-99
Full spelling of the%Y year
Python Time processing