10 examples of 'convert int to datetime python' in Python

Every line of 'convert int to datetime 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
82def str_to_dt(date):
83 ''' Converts Yahoo Date Strings to datetime objects. '''
84 yr = int(date[0:4])
85 mo = int(date[5:7])
86 day = int(date[8:10])
87 return datetime.datetime(yr,mo, day)
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)
98def string_to_datetime(string):
99 """
100 Takes a string formatted as follows yyyymmddhhmmss and returns a datetime.datetime object.
101 """
102 year=int(string[0:4])
103 month=int(string[4:6])
104 day=int(string[6:8])
105 hour=int(string[8:10])
106 min=int(string[10:12])
107 sec=int(string[12:14])
108
109 return datetime.datetime(year,month,day,hour,min,sec)
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 )
11def to_datetime(timestamp):
12 """Return datetime object from timestamp."""
13 return dt.fromtimestamp(time.mktime(
14 time.localtime(int(str(timestamp)[:10]))))
5def parse_datetime(datetime_str):
6 if datetime_str:
7 return datetime.strptime(datetime_str, '%Y-%m-%d %H:%M')
37def time_to_datetime(t):
38 return _combine_date_time(date.today(), t)
11def to_datetime(date_str: str) -> datetime:
12 d = date_str
13 try:
14 dte = datetime.strptime(d, "%Y-%m")
15 except ValueError:
16 dte = date_str
17 return dte
402def datetime_to_timestamp(dt):
403 """Converts a datetime object to UTC timestamp"""
404 return int(utc_mktime(dt.timetuple()))
37def parse_date(date):
38 # Sample: 2005-12-30
39 # This custom parsing works faster than:
40 # datetime.datetime.strptime(date, "%Y-%m-%d")
41 year = int(date[0:4])
42 month = int(date[5:7])
43
44 day = int(date[8:10])
45 ret = datetime.datetime(year, month, day)
46
47 return ret

Related snippets