Okay, now that we know how time is used on Linux, let's talk about some utilities.
First there is the old utility date. You can use it to check time and set
time, display format and even to set time. But it's not the most convenient utility.
Hwclock manipulates the hardware time and that is useful. Knowing that the software clock is based
on the hardware clock, you might first want to fix it in the hardware clock.
And there is Time datectl, which is the generic
utility that allows you to manage time related properties.
Let's go check it out.
So here we have the date utility which is showing the date in standard format. What I
like about date is formatting options. So date +% d percent m dash percent y for instance,
which is showing the day in the month and in the year. Make that an uppercase y
and you have a four digit year and make that an uppercase d and you have what?
Well, you have a different formatting.
Now the date formatting is quite convenient. Have a look at the man
page if you want to display your time in a certain format.
But if you really want to set the time, better go for time date ctl.
You step completion and there you can see all the different options.
So let's do a time date CTL show where we can see the current settings,
including the time zone and the current time that is set. And this current time
accurately matches what we currently have. So no need to use set time.
I mean nowadays nobody is setting the time anymore. You automatically get the time from the Internet.
In rare situations where your hardware clock is seriously off because of that, you
can't synchronize your time with the Internet anymore. You might want to use settime.
Let me do something more interesting like Time date ctl set time zone.
You can use list time zones if you don't know what exactly to use.
But if you do know, then you can set it to whatever you want.
Like Africa, Lusaka. And look at that, now we're in Lusaka.
Do we see that in time date CTL show? Yeah, we do. It's 2312 in Lusaka right now.
And if that is not what I want, well, let's
get back to set time zone America, Los Angeles.
And it automatically adjusts the time.
One thing that you might be interested in that is HW Clock.
HW Clock has a couple of useful options.
Help is showing these options.
So what are the options? Well, mainly it is
about sys to HC or HC to sys.
When do you want to use it? Well, if your hardware clock is off, then you can consider
using timedatectl to set your software clock correctly and then you are going to use HW clock minus
minus sys to HC to push your software clock to the hardware clock and then everything is all
right and your system should be capable of correctly doing an NTP time synchronization again.