Here's my problem. I created a livecd (on usb stick) that boots to a custom written program that I've written. The program relies on the HW clock being set to UTC time. i.e. when you issue the 'date' command, it shows UTC date/time. I have it set the OS to use NTP servers to get the time.
The
date command does
not read the hardware clock. Plain
date shows your system time as your local time,
date -u shows your system time as UTC time, but in neither case does it show the time your hardware clock is set to.
If you set your local time zone to UTC, then
date and
date -u will of course show the same time. Whether that
really is UTC depends on how you set your clocks....
When the computer is hard wired (Ethernet cable), the computer boots, connects to an NTP server, sets the time and everything works. However, if the computer is using Wi-Fi, the program boots and the time/date is set to local time, even after the computer connects to the Wi-Fi modem, and connects to the internet. It doesn't update the clock (either hardware or software clock) to UTC time, even though when I go into the setup program, it shows that the time zone is UTC.
With the information given I can't answer that. Is the NTP daemon running in both cases?
So, why doesn't it get updated? How long does it take for it to update, assuming that it actually WILL update the clocks? What's the proper way to handle or correct this situation? How can I make sure that the clocks are set to UTC, before letting my program run? Can I check to see if it can actually connect to a NTP server and get the time before running my program?
The command
ntpq -p
should show you whether you are connected or not. An asterisk in front of a server URL tells you that you are synchronized to that server, a plus sign that a server is good enough to use.
Note that the system clock is synchronized to the hardware clock at boot and the hardware clock to the system clock at shutdown. (With the line
[ -x /sbin/hwclock ] && action "Syncing hardware clock to system time" /sbin/hwclock --systohc
in
/etc/rc.d/init.d/halt.)
In between, the hardware clock is neither read nor written to unless you do it manually or have changed the default settings. (It's quite possible to let the system adjust the hardware clock every time the NTP daemon has adjusted the system time. Usually this wouldn't make sense though.)
I always thought (and have researched this) that the hardware clock is always set to UTC time, but MS Windows (and Linux) users can change this to local time, although they shouldn't.
Correct, although most forum members have their hardware clocks set to local time without any ill effects. (Some people get away with anything....)
Any help in how to solve my program would be greatly appreciated.