10 examples of 'datetime64 to datetime' in Python

Every line of 'datetime64 to datetime' 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
11def _epoch_utc_to_datetime(epoch_utc):
12 """
13 Helper function for converting epoch timestamps (as stored in JWTs) into
14 python datetime objects (which are easier to use with sqlalchemy).
15 """
16 return datetime.fromtimestamp(epoch_utc)
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

8def convert_to_datetime(datetime_str):
9 tweet_datetime = datetime.strptime(datetime_str,'%a %b %d %H:%M:%S %z %Y')
10
11 return(tweet_datetime)
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)
11def to_datetime(timestamp):
12 """Return datetime object from timestamp."""
13 return dt.fromtimestamp(time.mktime(
14 time.localtime(int(str(timestamp)[:10]))))
181def mk_datetime(string):
182 return datetime.datetime.fromtimestamp(time.mktime(email.utils.parsedate(string)))
37def time_to_datetime(t):
38 return _combine_date_time(date.today(), t)
5def parse_datetime(datetime_str):
6 if datetime_str:
7 return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M')
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)
209def localToUtcDateTime(dateTimeInLocal):
210 return getDateTimeInUTC(getTimestampFromLocal(dateTimeInLocal.timetuple()))
44def datetime_utc_to_datetime_local(datetime_utc, local_zone = None):
45 if local_zone is None :
46 from dateutil import tz
47 # Hardcode local zone
48 # local_zone = tz.gettz('America/Chicago')
49 # or Auto-detect local zone
50 local_zone = tz.tzlocal()
51 # Tell the datetime object that it's in local time zone since
52 # datetime objects are 'naive' by default
53 return datetime_utc.replace(tzinfo=local_zone)

Related snippets