10 examples of 'python get unix timestamp' in Python

Every line of 'python get unix timestamp' 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
13def timestamp():
14 return calendar.timegm(pytz.utc.localize(datetime.datetime.utcnow()).timetuple())
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

140def timestamp():
141 now_time = datetime.now()
142 if PY3:
143 return now_time.timestamp()
144 else:
145 epoch = datetime.utcfromtimestamp(0)
146 total_seconds = (now_time - epoch).total_seconds()
147 # total_seconds will be in decimals (millisecond precision)
148 return total_seconds
92def timestamp():
93 """Return a timestamp string."""
94 return str(datetime.datetime.now()).split('.')[0]
72def from_timestamp(unixtime):
73 """
74 Args:
75 unixtime (int):
76
77 Returns:
78 datetime.datetime:
79
80 """
81 if not unixtime:
82 return None
83
84 return datetime.fromtimestamp(unixtime)
15def _timestamp():
16 return time.strftime('[%Y-%m-%d %H:%M:%S] ', time.localtime(time.time()))
31def _timestamp():
32 return time.strftime("%Y-%m-%d-%H-%M-%S".format(time.gmtime(time.time())))
8def get_timestamp():
9 """Returns string ISO 8601 with hours:minutes:seconds"""
10 return time.strftime("%Y-%m-%d %H:%M:%S")
175def timestamp():
176 return time.strftime("%a %b %d %H:%M:%S %Y")
84def timestamp_to_unix(timestamp):
85 return str(int(timestamp))
35def timestamp():
36 """timestamp() -> str:timestamp
37
38 Returns a string of digits representing the current time.
39 """
40 return str(int(time.time() * 1000000))

Related snippets