/ examples / datetime_simpletest.py
datetime_simpletest.py
 1  # SPDX-FileCopyrightText: 2001-2021 Python Software Foundation.All rights reserved.
 2  # SPDX-FileCopyrightText: 2000 BeOpen.com. All rights reserved.
 3  # SPDX-FileCopyrightText: 1995-2001 Corporation for National Research Initiatives.
 4  #                         All rights reserved.
 5  # SPDX-FileCopyrightText: 1995-2001 Corporation for National Research Initiatives.
 6  #                         All rights reserved.
 7  # SPDX-FileCopyrightText: 1991-1995 Stichting Mathematisch Centrum. All rights reserved.
 8  # SPDX-FileCopyrightText: 2021 Brent Rubell for Adafruit Industries
 9  # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
10  # SPDX-License-Identifier: Python-2.0
11  
12  # Example of working with a `datetime` object
13  # from https://docs.python.org/3/library/datetime.html#examples-of-usage-datetime
14  from adafruit_datetime import datetime, date, time
15  
16  # Using datetime.combine()
17  d = date(2005, 7, 14)
18  print(d)
19  t = time(12, 30)
20  print(datetime.combine(d, t))
21  
22  # Using datetime.now()
23  print("Current time (GMT +1):", datetime.now())
24  
25  # Using datetime.timetuple() to get tuple of all attributes
26  dt = datetime(2006, 11, 21, 16, 30)
27  tt = dt.timetuple()
28  for it in tt:
29      print(it)
30  
31  print("Today is: ", dt.ctime())
32  
33  iso_date_string = "2020-04-05T05:04:45.752301"
34  print("Creating new datetime from ISO Date:", iso_date_string)
35  isodate = datetime.fromisoformat(iso_date_string)
36  print("Formatted back out as ISO Date: ", isodate.isoformat())