10 examples of 'python datetime from string' in Python

Every line of 'python datetime from string' 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
483def parse_datetime(string):
484 parser = DateTimeParser(string)
485 return parser.parse()
11def fromString(self, strDatetime):
12 return datetime.datetime.strptime( strDatetime, FMT8601String)
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)
93def parse_from_str(self, s):
94 """
95 Parses a string to a :py:class:`~datetime.datetime`.
96 """
97 try:
98 v = datetime.datetime.strptime(s, self.date_format)
99 return v.replace(tzinfo=pytz.UTC)
100 except (ValueError):
101 return pendulum.parse(s, tz=pytz.UTC)
26def to_datetime(string):
27 """Load UTC time as a string into a datetime object."""
28 try:
29 # Format is 2011-07-05 01:26:12.084316
30 return datetime.datetime.strptime(
31 string.split('.', 1)[0], '%Y-%m-%d %H:%M:%S')
32 except ValueError:
33 return datetime.datetime.strptime(string, '%Y-%m-%d')
61def parse_from_str(self, s):
62 """
63 Parses a date string formatted like ``YYYY-MM-DD``.
64 """
65 if s.lower() == DateAlias.today:
66 return utcnow().date()
67 elif s.lower() == DateAlias.yesterday:
68 return utcnow().date() - datetime.timedelta(days=1)
69 else:
70 return datetime.datetime.strptime(s, self.date_format).date()
441""" x.__eq__(y) <==> x==yx.__eq__(y) <==> x==yx.__eq__(y) <==> x==y """
442 pass
443
444def __format__(self, *args): #cannot find CLR method
445 """ __format__(formattable: IFormattable, format: str) -> str """
446 pass
447
448def __ge__(self, *args): #cannot find CLR method
449 pass
450
451def __gt__(self, *args): #cannot find CLR method
452 pass
453
454def __init__(self, *args): #cannot find CLR method
455 """ x.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signature """
456 pass
181def mk_datetime(string):
182 return datetime.datetime.fromtimestamp(time.mktime(email.utils.parsedate(string)))
28def from_utc_string(dt):
29 # type: (str) -> datetime
30 parsed = parsedate(dt)
31 # fix for python < 3.6
32 if not parsed.tzinfo:
33 parsed = parsed.replace(tzinfo=pytz.utc)
34 return parsed.astimezone(pytz.utc)
95def stringToDateTime(string):
96 """
97 Converts a string to a DateTime if the format is known
98 """
99 try:
100 if string:
101 return dateutil.parser.parse(string)
102 return None
103 except:
104 raise InputException(u'Format of Date "{0}" is unknown'.format(string))

Related snippets