Kali Linux 2018.1时钟异常求助:date -u与hwclock -u结果不一致
Hey, let's work through this clock issue you're facing. The key clue here is that hwclock -u gives the correct time—this tells me your hardware clock (RTC) is properly set to UTC, but something's off with how your system is interpreting or syncing that time. Let's break down the fixes step by step:
1. Check Your Timezone Configuration
First, make sure your system is using the right timezone. Run this to see your current setup:
timedatectl
Look for the Time zone line—if you're in a region like China, it should say Asia/Shanghai (CST, +0800). If it's wrong (like showing UTC or another mismatched timezone), set it correctly with:
sudo timedatectl set-timezone Asia/Shanghai
(Replace Asia/Shanghai with your actual timezone, e.g., Europe/London if you're in the UK.)
2. Ensure Hardware Clock Uses UTC Mode
Linux expects the hardware clock to store UTC time, then converts it to local time based on your timezone. If your system is treating the RTC as local time, that'll cause the 1-hour mismatch. Check with:
timedatectl | grep "RTC in local TZ"
If the output says yes, fix it by switching to UTC mode:
sudo timedatectl set-local-rtc 0
3. Sync System Clock to the Correct Hardware Clock
Now we'll force the system clock to match the correct UTC time from your hardware clock:
sudo hwclock --hctosys --utc
This command takes the time from the hardware clock (HC) and sets the system clock (SYS) to match, using UTC as the reference.
4. Enable NTP for Automatic Time Sync (Recommended)
To prevent this issue from coming back, turn on NTP to keep your clock automatically synced with reliable time servers:
sudo timedatectl set-ntp on
Verify it's working by checking:
timedatectl | grep "NTP synchronized"
You should see yes if it's active and syncing properly.
Test the Fix
Reboot your system, then run these commands to confirm everything's working as expected:
date: Should show your correct local timedate -u: Should match the output ofhwclock -u(both are UTC time)hwclock: Should show your local time (since it converts the UTC hardware clock to your configured timezone)
内容的提问来源于stack exchange,提问作者Engo

