Simple test

Ensure your device works with this simple test.

examples/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
14from adafruit_datetime import datetime, date, time
15
16# Using datetime.combine()
17d = date(2005, 7, 14)
18print(d)
19t = time(12, 30)
20print(datetime.combine(d, t))
21
22# Using datetime.now()
23print("Current time (GMT +1):", datetime.now())
24
25# Using datetime.timetuple() to get tuple of all attributes
26dt = datetime(2006, 11, 21, 16, 30)
27tt = dt.timetuple()
28for it in tt:
29    print(it)
30
31print("Today is: ", dt.ctime())
32
33iso_date_string = "2020-04-05T05:04:45.752301"
34print("Creating new datetime from ISO Date:", iso_date_string)
35isodate = datetime.fromisoformat(iso_date_string)
36print("Formatted back out as ISO Date: ", isodate.isoformat())