How to use 'how to calculate time in python' in Python

Every line of 'how to calculate time in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
27def compute_time(is_hourly):
28 """Figure out the proper start and end time"""
29 utcnow = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
30 utcnow = utcnow.replace(minute=0, second=0, microsecond=0)
31
32 if is_hourly:
33 lasthour = utcnow - datetime.timedelta(minutes=60)
34 sts = lasthour.replace(minute=0)
35 ets = lasthour.replace(minute=59)
36 else:
37 yesterday = utcnow - datetime.timedelta(hours=24)
38 sts = yesterday.replace(hour=0)
39 ets = sts.replace(hour=23, minute=59)
40 return sts, ets
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

170def testTimeStuff():
171 print("-"*20)
172 print()
173 print("The GPS Epoch when everything began (1980, 1, 6, 0, 0, 0, leapSecs=0)")
174 (w, sow, d, sod) = gpsFromUTC(1980, 1, 6, 0, 0, 0, leapSecs=0)
175 print("**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod))
176 print(" and hopefully back:")
177 print("**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow, leapSecs=0))
178
179 print("The time of first Rollover of GPS week (1999, 8, 21, 23, 59, 47)")
180 (w, sow, d, sod) = gpsFromUTC(1999, 8, 21, 23, 59, 47)
181 print("**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod))
182 print(" and hopefully back:")
183 print("**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow, leapSecs=14))
184
185 print("Today is GPS week 1186, day 3, seems to run ok (2002, 10, 2, 12, 6, 13.56)")
186 (w, sow, d, sod) = gpsFromUTC(2002, 10, 2, 12, 6, 13.56)
187 print("**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod))
188 print(" and hopefully back:")
189 print("**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow))

Related snippets