0

Find Current Time
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Find Current Time

by fredb1 on Sun Feb 17, 2019 4:56 pm

As noted in other posts, CircuitPython does not support the datetime module of C python. I looked at some of the micropython docs regarding the time module, could not find what I was looking for. I understand that one has to set the RTC to get the current time, but I'm not sure how to do that. I am using a Feather M0 Express and would appreciate any help. -- Thanls

fredb1
 
Posts: 1
Joined: Wed Aug 15, 2012 10:27 pm

Re: Find Current Time

by tannewt2 on Tue Feb 19, 2019 3:11 am

We generally recommend using an external RTC that has a battery. That way you only need to set the time once. Some options are here: https://www.adafruit.com/?q=rtc

To use the built-in RTC you can do something like:
Code: Select all | TOGGLE FULL SIZE
import rtc
import time
clock = rtc.RTC() # Get the rtc singleton
print(clock.datetime) # Print to see the constructor format of struct_time to use below
clock.datetime = time.struct_time((....))
print(clock.datetime) # up to date time


This will only maintain time while the feather has power though.

Let us know how it goes!

tannewt2
 
Posts: 976
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.