10 examples of 'timestamp to date python' in Python

Every line of 'timestamp to date 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
48def timestamp_to_date(timestamp: int) -> datetime.date:
49 return datetime.datetime.fromtimestamp(timestamp).date()
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

53def timestamp2date(tstamp):
54 "Converts a unix timestamp to a Python datetime object"
55 dt = datetime.fromtimestamp(tstamp)
56 if not dt.hour + dt.minute + dt.second + dt.microsecond:
57 return dt.date()
58 else:
59 return dt
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
16def timestamp2datetime(timestamp: int):
17 date = datetime.datetime.fromtimestamp(timestamp / 1000)
18 return date
44def date_to_timestamp(d: datetime.date) -> int:
45 return (datetime.datetime.combine(d, datetime.datetime.min.time()) - epoch).total_seconds()
11def to_datetime(timestamp):
12 """Return datetime object from timestamp."""
13 return dt.fromtimestamp(time.mktime(
14 time.localtime(int(str(timestamp)[:10]))))
263def pyCalendarToSQLTimestamp(pydt):
264
265 if pydt.isDateOnly():
266 return date(year=pydt.getYear(), month=pydt.getMonth(), day=pydt.getDay())
267 else:
268 return datetime(
269 year=pydt.getYear(),
270 month=pydt.getMonth(),
271 day=pydt.getDay(),
272 hour=pydt.getHours(),
273 minute=pydt.getMinutes(),
274 second=pydt.getSeconds(),
275 tzinfo=None
276 )
83def datetime_to_timestamp(dt_):
84 """Convert given datetime object to timestamp in seconds."""
85 return dt_.replace(tzinfo=dt.timezone.utc).timestamp()
14def datetimeAsTimestamp(dt):
15 return dt.timestamp()
7def timestamp_to_datetime(s):
8 """
9 Convert a Core Data timestamp to a datetime. They're all a float of seconds since 1 Jan 2001. We calculate
10 the seconds in offset.
11 """
12 if not s:
13 return None
14
15 OFFSET = (datetime.datetime(2001, 1, 1, 0, 0, 0) - datetime.datetime.fromtimestamp(0)).total_seconds()
16 return datetime.datetime.fromtimestamp(s + OFFSET)

Related snippets