kadina kadina - 1 year ago 82
C Question

How to check if the system time is valid or not in linux

Our devices have Linux OS installed on them. When the box reboots, it will contact the servers, get the time from servers and this time will be set as local time on the device. Can any one please let me know if there is any way to check whether this time is valid or not.

Answer Source

In C, time() returns (time_t)(-1) to indicate "the calendar time is not available."

If mkitme() fails, it returns (time_t)(-1) when "the calendar time cannot be represented".

Testing the result of time() may be a sufficient "way to check whether this time is valid or not."

The value (time_t)(-1) is returned if the calendar time is not available. C11dr ยง7.27.2.4 3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download