10 examples of 'python get utc time' in Python

Every line of 'python get utc time' 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
14def get_utc_now():
15 return datetime.datetime.now(pytz.utc)
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

46def get_utc(self):
47 # Returns a datetime object instead the string. Is this a good idea?
48 value = self._get_sub_text('utc')
49 if '.' in value:
50 return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%fZ')
51 else:
52 return datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
13def timestamp():
14 return calendar.timegm(pytz.utc.localize(datetime.datetime.utcnow()).timetuple())
103def get_utc_time(self,rawtime,fmt='datenum'):
104 utc = time.strptime(rawtime,'%m/%d/%Y (%H:%M)')
105 if fmt == 'datenum':
106 utc = calendar.timegm(utc)
107 return utc
43def get_gmt_time():
44 seconds = time.time() + 24 * 3600
45 st = time.localtime(seconds)
46 return time.strftime('%a, %d %b %Y %H:%M:%S GMT', st)
66def fromutc(self, dt):
67 assert dt.tzinfo is self
68 stamp = (dt - datetime(1970, 1, 1, tzinfo=self)) // SECOND
69 args = time.localtime(stamp)[:6]
70 dst_diff = DSTDIFF // SECOND
71 # Detect fold
72 fold = (args == time.localtime(stamp - dst_diff))
73 return datetime(*args, microsecond=dt.microsecond,
74 tzinfo=self, fold=fold)
53def utcstr(dt):
54 """
55 Convert an UTC datetime instance into an ISO 8601 combined date and time,
56 like i.e. 2011-11-23T12:23Z
57 """
58 try:
59 return dt.strftime(UTC_TIMESTAMP_FORMAT)
60 except:
61 return None
33def get_local_time(utc_time):
34
35 return utc_time.astimezone(est).replace(tzinfo=None)
120def get_local_time(dt: datetime.datetime = None, tz_default=UTC):
121 """
122 :param dt: 为None时,返回当前时间
123 :param tz_default: dt无时区信息时的默认时区
124 :return:
125 """
126 if dt is None:
127 dt = get_utc_time()
128 return convert_zone(dt, LocalTimeZone, tz_default)
187def timetz(self) -> _time: pass

Related snippets