10 examples of 'python timestamp format' in Python

Every line of 'python timestamp format' 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
42def timeStamp(dt=None, format='%Y-%m-%d_%H%M%S'):
43 if dt is None:
44 dt = datetime.now()
45 return dt.strftime(format)
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

65def parse_timestamp(format, timestamp_str):
66 """Utility function to parse a timestamp into a datetime.datetime.
67
68 Python 2.5 and up have datetime.strptime, but Python 2.4 does not,
69 so we roll our own as per the documentation.
70
71 If passed a timestamp_str of None, we will return None as a convenience.
72 """
73 if not timestamp_str:
74 return None
75
76 return datetime.datetime(*time.strptime(timestamp_str, format)[0:6])
52def formatTimestamp(timestamp):
53 return time.strftime("%Y%m%d %H:%M:%S", time.localtime(timestamp)) + ".%3.3d" % int((timestamp * 1000) % 1000)
9def _fmt(timestamp):
10 return timestamp.strftime('%Y-%m-%dT%H%M%S.%f')
179@classmethod
180def timestamp_to_date(cls, timestamp):
181 """
182 Transform unix :attr:`timestamp` to a data string in ISO format.
183
184 .. note:: This is a `classmethod`.
185
186 :param timestamp: A unix timestamp indicating a specified time.
187 :type timestamp: number
188
189 .. note:: The :attr:`timestamp` could be `int` or `float`.
190
191 :return: Date in ISO format, which is `YY-mm-dd` in specific.
192 :rtype: str
193 """
194 l_time = time.localtime(float(timestamp))
195 iso_format = "%Y-%m-%d"
196 date = time.strftime(iso_format, l_time)
197 return date
47def timestamp_str(timestamp):
48 return timestamp.isoformat() if timestamp else None
46def date(__format):
47 d = datetime.datetime.utcnow()
48 return d.strftime(__format)
600def _convert_to_custom_timestamp(self, dt, format):
601 if not self._need_to_handle_f_directive(format):
602 return dt.strftime(format)
603 format = self._remove_f_from_format(format)
604 return dt.strftime(format) + '%06d' % dt.microsecond
37def format_timestamp(val):
38 return '' if val is '' else int(dt.strptime(val, '%a %b %d %H:%M:%S %z %Y').timestamp())
252def get_timestamp(t=None):
253 if t is None:
254 return time.strftime("%Y-%m-%d %H:%M:%S")
255 elif len(t) == 8:
256 return time.strftime("%Y-%m-%d ") + t
257 else:
258 return t

Related snippets