10 examples of 'epoch to datetime python' in Python

Every line of 'epoch to datetime 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
101def epoch2datetime(epoch):
102 return datetime.datetime.utcfromtimestamp(epoch)
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

11def _epoch_utc_to_datetime(epoch_utc):
12 """
13 Helper function for converting epoch timestamps (as stored in JWTs) into
14 python datetime objects (which are easier to use with sqlalchemy).
15 """
16 return datetime.fromtimestamp(epoch_utc)
54def totimestamp(inputdate, epoch=datetime(1970,1,1)):
55 dt = datetime.strptime(inputdate, '%Y-%m-%d')
56 td = dt - epoch
57 timestamp = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6 # td.total_seconds()
58 return int(timestamp)
605def datetime_to_timestamp(dt):
606 if isinstance(dt, datetime.datetime):
607 return calendar.timegm(dt.utctimetuple())
608 return dt
24def _epoch_utc_to_arrow(epoch_utc):
25 """
26 生成arrow时间
27 """
28 time = arrow.get(epoch_utc)
29 return arrow.get(time.astimezone(tz.gettz("Asia/Shanghai")))
11def to_datetime(timestamp):
12 """Return datetime object from timestamp."""
13 return dt.fromtimestamp(time.mktime(
14 time.localtime(int(str(timestamp)[:10]))))
37def time_to_datetime(t):
38 return _combine_date_time(date.today(), t)
502def to_utc_dt(self):
503 return datetime.datetime.utcfromtimestamp(self.value//1000)
14def datetimeAsTimestamp(dt):
15 return dt.timestamp()
83def datetime_to_timestamp(dt_):
84 """Convert given datetime object to timestamp in seconds."""
85 return dt_.replace(tzinfo=dt.timezone.utc).timestamp()

Related snippets