This article mainly introduces python's detailed information on obtaining time instances with a specified time difference. For more information about how to obtain time instances with a specified time difference, see the next article, for more information, see
How to obtain a time instance with a specified time difference in python
Data that needs to be analyzed within a certain period of time, such as data required by the time within three days, two hours ago, is often intercepted. Therefore, this part of frequently used functions are modularized, this facilitates reuse later. I would like to share this with you.
Import time import sys reload (sys) def get_day_of_day (UTC = False, days = 0, hours = 0, miutes = 0, seconds = 0 ): ''''' if days> = 0, date is larger than today if days <0, date is less than today date format = "YYYY-MM-DD" ''' now = time. time () timeNew = now + days * 24*60*60 + hours * 60*60 + miutes * 60 + seconds if UTC: timeNew = timeNew + time. timezone t = time. localtime (timeNew) return time. strftime ('% Y-% m-% d % H: % M: % s', t) # use UTC time two hours ago t = get_day_of_day (True, 0, -2) print t #3 days before local time t = get_day_of_day (False,-3) print t #3 days after local time t = get_day_of_day (False, 3) print t
Result after running:
20:25:56 20:25:56
The above shows you how to use python to obtain detailed information about the specified time difference. For more information, see other related articles in the first PHP community!