Python gets detailed explanations of time instances with a specified time difference, and python Time Difference
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
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!