10 examples of 'python datetime from isoformat' in Python

Every line of 'python datetime from isoformat' 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
81def parse_datetime(dt: str) -> datetime:
82 return datetime.fromisoformat(dt[:-4])
20def test_fromisoformat(self):
21 # Test that isoformat() is reversible
22 base_dates = [
23 (1, 1, 1),
24 (1000, 2, 14),
25 (1900, 1, 1),
26 (2000, 2, 29),
27 (2004, 11, 12),
28 (2004, 4, 3),
29 (2017, 5, 30)
30 ]
31
32 for date_cls in [datetime, date]:
33 for dt_tuple in base_dates:
34 dt = date_cls(*dt_tuple)
35 dt_str = dt.isoformat()
36 with self.subTest(dt_str=dt_str):
37 dt_rt = date_cls.fromisoformat(dt.isoformat())
38
39 self.assertEqual(dt, dt_rt)
40 self.assertIsInstance(dt_rt, date_cls)
217def parse_isoformat(self, s):
218 return datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%f')
406def _iso8601(dt):
407 """Turn a datetime object into an ISO8601 formatted date.
408
409 Example::
410
411 fields._iso8601(datetime(2012, 1, 1, 0, 0)) => "2012-01-01T00:00:00"
412
413 :param dt: The datetime to transform
414 :type dt: datetime
415 :return: A ISO 8601 formatted date string
416 """
417 return dt.isoformat()
582def _to_isoformat(object):
583 """
584 Convert a datetime into the specifc ISO 8601 format required by the RCSB.
585 """
586 return object.strftime("%Y-%m-%dT%H:%M:%SZ")
25def simplified_isoformat_datetime(datetime_object):
26 return datetime_object.strftime('%Y-%m-%d %H:%M')
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)
149def datetime_(data, tz=None):
150 result = datetime.datetime(dt_bytes(data)).isoformat()
151 if tz is not None:
152 result = Instance("datetime", (), dict(value=result, tz=tz))
153 return result
47def datetime_iso_format(value):
48 """
49 Serialise a datetime.datetime to ISO string format.
50 """
51 # type: (datetime.datetime) -> str
52 return value.isoformat()
209def isoformat(self, sep='T'):
210 """
211 Convert object to an ISO 8601 timestamp accepted by MediaWiki.
212
213 datetime.datetime.isoformat does not postfix the ISO formatted date
214 with a 'Z' unless a timezone is included, which causes MediaWiki
215 ~1.19 and earlier to fail.
216 """
217 return self.strftime(self._ISO8601Format(sep))

Related snippets