Learn How to Check Server Time with Linux Command(linux查看服务器时间)

As most Linux users know, accurate server time is essential for a Linux server to function reliably. It’s important to ensure your server’s time is correctly synchronized with the rest of the world. This tutorial will demonstrate how to check the server time with a Linux command.

It’s relatively easy to check server time with the Linux terminal. Before checking the server’s time, you need to find out what the current local time is. To check the local time, use the `date` command:

“`bash

$date

Sat Jan 25 13:14:26 UTC 2020


The output will display the current local time on your server. Now that we’ve checked the local time, let’s check the server time. To check the server time, you need to use the `timedatectl` command. This command will show you the current time and date on your server, as well as the timezone.

```bash
$timedatectl
Local time: Sat 2020-01-25 13:15:21 UTC
Universal time: Sat 2020-01-25 13:15:21 UTC
RTC time: Sat 2020-01-25 13:15:21
Time zone: UTC (UTC, +0000)

The output of this command will display the server time along with the current time zone. The command also provides additional information, such as the RTC time, which is useful if you’re troubleshooting time-related issues on your server.

If you need to change the current timezone on your server, you can use the `timedatectl` command with the `set-timezone` option:

“`bash

$timedatectl set-timezone Europe/London

Local time: Sat 2020-01-25 14:15:21 UTC


This command will set the timezone on your server to Europe/London. You can also use the `timedatectl` command to set the time manually. This can be useful if your server time is off by a few seconds or minutes. To manually set the time on your server, use the `set-time` option:

```bash
$timedatectl set-time "2020-01-25 14:15:21"
Local time: Sat 2020-01-25 14:15:21 UTC

This command will set the server time to a specific date and time. In this example, the server time is set to Jan 25, 2020 at 14:15 UTC.

Finally, if you need to manually sync the server time to an NTP (Network Time Protocol) server, you can use the `sntp` command. The sntp command will sync the time with a NTP server of your choice. Here is an example using the sntp command to sync time with the “pool.ntp.org” NTP server:

“`bash

$sntp -s pool.ntp.org


This command will sync your server’s time with the “pool.ntp.org” NTP server. With the steps outlined in this tutorial, you’ll be able to properly check and sync your server time with the rest of the world.

数据运维技术 » Learn How to Check Server Time with Linux Command(linux查看服务器时间)