# Using time.localtime() vs RTC.datetime()

**URL:** <https://forums.openmv.io/t/using-time-localtime-vs-rtc-datetime/11190>\
**Category:** OpenMV Boards\
**Created:** [July 1, 2025, 7:23pm UTC](https://forums.openmv.io/t/using-time-localtime-vs-rtc-datetime/11190 "2025-07-01T19:23:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdrezen](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@cdrezen](https://forums.openmv.io/u/cdrezen)\
**Post date:** [July 1, 2025, 7:23pm UTC](https://forums.openmv.io/t/using-time-localtime-vs-rtc-datetime/11190/1 "2025-07-01T19:23:53Z")

</div>

Hello,  
I was working on some code and I noticed the usage of both _time.localtime()_ and _RTC.datetime()_ to get the current date. The code is supposed to set the date of the internal rtc on power on.

```auto
### timeutil module ###
import machine, pyb

class Rtc:
    def __init__ (self):
        # initialise RTC object
        self.rtc = pyb.RTC()
        # set rtc from user defined date and time only on power on
        if (machine.reset_cause() != machine.DEEPSLEEP_RESET):
            self.rtc.datetime(cfg.START_DATETIME)
        
    def datetime(self):
        return self.rtc.datetime() # returns a tuple (year, month, day, weekday, hours, minutes, seconds, subseconds)

    
rtc = Rtc()

clock = time.clock()

def datetime():
    return rtc.datetime()

```

Is there any reason to use one over the other to get the current date ? If not I don’t think I need to keep my Rtc object.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [July 1, 2025, 10:28pm UTC](https://forums.openmv.io/t/using-time-localtime-vs-rtc-datetime/11190/2 "2025-07-01T22:28:35Z")

</div>

It’s going to be the same. modtime.c for each port just calls the HAL layer for the port to get the current RTC time.
