10 examples of 'convert timestamp to string python' in Python

Every line of 'convert timestamp to string 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
117def timestamp_to_str(timestamp):
118 """Convert epoch timestamp to a time string in UTC.
119
120 Args:
121 timestamp: The epoch time, in seconds, to convert.
122 Returns:
123 String representation of the timestamp in UTC timezone.
124 """
125 if not timestamp:
126 return ''
127 if timestamp == sys.maxint:
128 # sys.maxint represents infinity.
129 return 'inf'
130 utc = pytz.timezone('UTC')
131 return datetime.datetime.fromtimestamp(timestamp, tz=utc).strftime(
132 '%Y-%m-%d %H:%M:%S %Z')
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

47def timestamp_str(timestamp):
48 return timestamp.isoformat() if timestamp else None
11def timestamp_to_SQLstring(timestamp):
12 return str(timestamp)[:-6]
43def timestampToString(value):
44 return asctime(time.gmtime(max(0, value + epoch_diff)))
52def time_object_to_string(time_object):
53 return datetime.strftime(time_object, '%Y-%m-%d %H:%M:%S')
84def timestamp_to_unix(timestamp):
85 return str(int(timestamp))
11def to_datetime(timestamp):
12 """Return datetime object from timestamp."""
13 return dt.fromtimestamp(time.mktime(
14 time.localtime(int(str(timestamp)[:10]))))
59def convert_timestamp_to_mysql(timestamp):
60 """
61 Convert timestamp to correct format for MySQL
62
63 :param timestamp: string containing timestamp in APIC format
64 :return: string containing timestamp in MySQL format
65 """
66 (resp_ts, remaining) = timestamp.split('T')
67 resp_ts += ' '
68 resp_ts = resp_ts + remaining.split('+')[0].split('.')[0]
69 return resp_ts
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
48def timestamp_to_date(timestamp: int) -> datetime.date:
49 return datetime.datetime.fromtimestamp(timestamp).date()

Related snippets