1

I am running Pi 3 along with Real-Time Clock chip ds1302 and using wiringPI library to read and set date and time to and from ds1302 chip. After I set my Pi's system date and time to local date and time in 12 hour format, I set the Real Time Clock ds1302 chip its date and time by sudo ./ds1302 -sdsc Then, I read what was written into clock chip and it reads back UTC time in 24 hour format. So, then I continued with the test by issuing sudo ./ds1302 -slc to set the Pi's date and time from clock chip date and time. Now, my pi's time is one hour ahead in 12 hour format. I am confused. Is there way to force wiringpi library to use only local time in 12 hour format?

1
  • You could always try reading the data sheet. I would just throw this obsolete chip, which is not supported by Device Tree and is not a particularly good RTC, and use a more modern chip, such as DS3231
    – Milliways
    Dec 22, 2016 at 0:37

2 Answers 2

4

The use of UTC time seems to be hardcoded in ds1302 utility. Note the following line:

gmtime_r (&now, &t) ;

This converts your system time to UTC, before writing it to the DS1302 chip. When the chip is read back, your system time is set to whatever is received from the chip, without any conversion (which frankly looks like a bug).

There are two things you can do:

  1. replace gmtime_r with localtime_r and recompile. Hopefully, you will have your local time in both RPi and DS1302.

  2. configure your RPi to use UTC time with raspi-config. Then the conversion done by gmtime_r will be identical to localtime_r. Whether using UTC time is convenient to you is another story.

0

Linux uses UTC. So many subsystems depend on it that you'd be better off doing a localtime conversion for the times you need, and let the system clock run on UTC as it's supposed to.

You should be able to use hwclock to set and retrieve the time from a 1302. It should make the conversion to/from UTC for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.