0

The question may sound stupid, but here's my case: I have a C++ program on Jetson Nano (a Single Board Computer) and want to get current time and date. In my application however, I can't always connect the internet cable to the device. Although in the Ubuntu settings I told it to automatically get the time from the internet, when it powers on after a longer time period (when it was not connected to power), the system clock gets confused and has a completely wrong time and date. This is what my C++ program (using std::chrono::system_clock()) then picks up.

Is there a way to get around this issue? Somehow, make does know when system time and date are set incorrect even if the device is not connected to the internet. I can tell because it fails when trying to compile with "Clock skew detected". How can I get the correct time and date when not connected to the internet?

Totemi1324
  • 468
  • 1
  • 6
  • 19
  • 2
    Unless you have a battery on your device to save the date, you can't. There are quite a few hits for "Jetson Nano RTC", look around. (Make just looks at file timestamps. It complains if it finds build outputs created in the future IIRC.) – Mat Jan 01 '21 at 14:57
  • As a fallback, your program can periodically save out the last known time to a file. Then it can compare current time to last known time and if current time is earlier it can use the offset of current time at start compared to current time, and add that delta to last known time, and use that calculated time. My BBS in the 1980s used that method, because if it lost power the RTC would be incorrect (because the battery failed). – Eljay Jan 01 '21 at 15:18
  • see [How to add a correct battery for RTC on Jetson Nano](https://forums.developer.nvidia.com/t/how-to-add-a-correct-battery-for-rtc-on-jetson-nano/74780) if you haven't done it – phuclv Jan 01 '21 at 15:52

1 Answers1

1

Somehow, make does know when system time and date are set incorrect even if the device is not connected to the internet.

'Fraid not.

It merely spots that the time has gone backwards since the last time it checked, and knows that this is not naturally how time works. It's guessing. The clock could be wrong now, it could have been wrong before, or it could be wrong both times.

A clock is where you get the time from. If you don't have a clock, you don't have the time. ‍♂️ And if you do have a clock (as most computers do, including yours), but it's not traceable (e.g. by a NTP server connected to a local time server, or one on the internet), you'll never be able to trust it.

You have a clock that's not traceable, and already unreliable because apparently no battery is present to let it keep time over the long term. If you want to know the time, you'll need to fix at least one, ideally both, of these problems.

Fortunately, it seems to be possible to install a backup battery for your Real-Time Clock, which solves the reliability. Without traceability you'd still be relying on the clock's own properties, and it may gradually lose or gain time, but if you manually set it once then you'll at least be in the ballpark for a good while. You can look up the clock's specs to find out how large that ballpark is, and thus how often you may need to update the time from another source (e.g. wristwatch!).

Asteroids With Wings
  • 17,071
  • 2
  • 21
  • 35