When processing data and machine learning, there are a number of time series that need to be processed. For example, the database reads the STR and time conversions, and the time difference is calculated. Summarize Python's time-processing content and hope to help you learn python.conversion of a string and time series·time.strptime (): string = Time series ·time.strftime (): Time Series = string Import TimeStart = "2017-01-01" end = "2017-8-12" StartTime = Time.strptime (Start, "%y-%m-%d") EndTime = Time.strptime (end, "%y-%m-%d" ) # The second parameter format specifies formattingPrint(StartTime);Print(endTime) _start = Time.strftime ('%y%m%d-%h:%m:%s ', startTime) _end = Time.strftime ('%y%m%d-%h:%m:%s ', endTime) # The parameter position is exactly the oppositePrint(_start)Print(_end)second, time stamp·time.mktime (t): Converts t to timestamp ·Time.localtime (s): Converts timestamp to time Startstamp = Time. Mktime (StartTime) # Time= time stamp Endstamp = Time. Mktime (endTime) print (startstamp) print (endstamp) _starttime = Time. LocalTime (startstamp) # timestamp = TimePrint (_starttime)third, date arithmeticNote: The timestamp is starting from 1970, in seconds, so our calculations can be based on the number of secondsFor example, here I calculate the number of days between StartTime and EndTime: print (int((Endstamp-startstamp)/(24*60*60)))Iv. Summary of the format%a English week abbreviation%a English week full%b English month abbreviation%b English month full%c show local datetime%d date, take 1-31%h hour, 0-23%i Hours, 0-12%m months, 01-12%m minutes, 1-59%j days of the day%w show today is the day of the week%w first week%x date%x local day time%y year 00-99 full spelling of%y yearSource: Blog Park
Python Time processing