10 examples of 'pandas convert timestamp to date' in Python

Every line of 'pandas convert timestamp to date' 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
30def converter(df: DataFrame) -> Series:
31 return df[field_name]
48def timestamp_to_date(timestamp: int) -> datetime.date:
49 return datetime.datetime.fromtimestamp(timestamp).date()
16def timestamp2datetime(timestamp: int):
17 date = datetime.datetime.fromtimestamp(timestamp / 1000)
18 return date
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
83def datetime_to_timestamp(dt_):
84 """Convert given datetime object to timestamp in seconds."""
85 return dt_.replace(tzinfo=dt.timezone.utc).timestamp()
150def utc_timestamp_to_datetime(timestamp):
151 """
152 Converts the given timestamp to a datetime instance.
153
154 :type timestamp: float
155 :rtype: datetime
156 """
157
158 if timestamp is not None:
159 return datetime.fromtimestamp(timestamp, utc)
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)
50def timestamp_to_datetime(ts):
51 """
52 Convert timestamps to datetime objects
53 """
54 if ts is None:
55 return None
56 if isinstance(ts, (str, bytes)):
57 ts = float(ts)
58 return datetime.datetime.utcfromtimestamp(ts)
528def _convert_date_format(frame, date_format=None):
529 if date_format is not None:
530
531 def _convert(col):
532 if col.dtype.name == "datetime64[ns]":
533 return col.apply(lambda x: x.strftime(date_format))
534 return col
535
536 frame = frame.apply(_convert)
537 return frame

Related snippets