Datasheet

At this point you're read to read and even set the time of the clock. You just need to interact with the datetime
property of the DS3231 instance. For example to read it you can run:
Notice the time is returned as a special Python time structure. This is from the time module in Python and it has
properties like:
tm_year - The year of the timestamp
tm_mon - The month of the timestamp
tm_mday - The day of the month of the timestamp
tm_hour - The hour of the timestamp
tm_min - The minute of the timestamp
tm_sec - The second of the timestamp
tm_wday - The day of the week (0 = Monday, 6 = Sunday)
tm_yday - The day within the year (1-366)
tm_isdst - 0 if not in daylight savings, 1 if in savings, and -1 if unknown
Also notice if the time hasn't been set it defaults to a value of January 1st, 2000 (wow Y2K retro!).
You can write to the datetime property to set the time of the clock, for example to set it to January 1st, 2017, at
midnight local time you could run:
Notice the parameters to the struct_time initializer, you must pass in a tuple of all the values listed above.
Now if you read the datetime property you'll see the clock is running from the set time. For example if you want to
read and print out just the year, month, day, hour, minute, and second you could run:
import adafruit_ds3231
ds3231 = adafruit_ds3231.DS3231(i2c)
ds3231.datetime
import time
ds3231.datetime = time.struct_time((2017, 1, 1, 0, 0, 0, 6, 1, -1))
current = ds3231.datetime
print('The current time is: {}/{}/{} {:02}:{:02}:{:02}'.format(current.tm_mon, current.tm_mday, current.tm_year
© Adafruit Industries https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout Page 18 of 22