Server time change linux

How to change ubuntu’s server date and time via command line?

The Ubuntu server’s current date and time is different from the time zone date and time. I have tried using:

sudo date "30 Sep 2015 4:43:42" 

to change it but it did not change the date and time, just printed on terminal the date and time I changed, but when I executed:

The date and time is still the old one. What is the correct way to change date and time of Ubuntu Server?

7 Answers 7

You can set the system date with this command:

sudo date --set="2015-09-30 10:05:59.990" 

Then when using date , it should be showed correctly.

Now you should also the set hardware clock in the BIOS of the system, that the setting persists over a reboot (dureing the startup the system time is set to the value of the hardware clock). Do that with hwclock :

This gets the system clocks (sys) value and sets the hardware clock (hc). Check it with the hwclock command. Both hwclock and date should now show the same date and time.

To set your timezone, you can use this command:

sudo dpkg-reconfigure tzdata 

BTW: If you use a this machine as a server, I strongly recommend using an NTP-Client to sync the time over network. So you can guarantee that all your servers have the exactly same time set. This will sync the time while the machine runs. If you have applications which are dependent of synced time over server, I recommend the NTP-Daemon. The longer it runs in the background, the more precise is the time.

Источник

How to Change/Set Date, Time, & Timezone on a Linux Server

The date, time, and timezone are important aspects of a Linux system that affect how it operates and interacts with other systems. There are different ways to describe and change these settings in Linux, depending on the distribution and the tools available. Below you will find information on how to display the current date, manually change the system date and time, and set timezones in Linux using the command line and these simple commands.

Display Date in Linux

You can use the date command to display the current date and time:

Screenshot showing the result of the date command.

Using Menu-Based Time Zone Selection

tzselect is a Linux utility that allows users to select a timezone from a list of regions and cities. The utility outputs the timezone description to standard output, which can be used as a value for the TZ environment variable. tzselect does not change the system timezone permanently, it only affects the current shell session. To change the system timezone permanently, other methods such as timedatectl or symlinking can be used, although at the end of this prompt you will see the method used with tzselect to make the change persistent.

Читайте также:  No such file or directory linux executable

Begin by running the following command:

Screenshot showing the results of the tzselect command.

For this example, we select 2 for Americas. Next, select the country.

Screenshot showing a list of available countries.

For this example we will select 10 for Canada.

Screenshot showing a list of available timezones.

Then the next screen will display the selection made along with checking whether the information is correct.

Screenshot showing the selection of Canada with a Pacific timezone and asking for confirmation.

Once we confirm the selection you can view the details changed below. This screen also provides information on how to keep the change persistent by appending a line to the .profile file in your home directory.

Screenshot showing confirmation of the information entered above.

Changing Time Zone Using timedatectl

timedatectl is a command-line utility that allows you to view and change the system time, date, and timezone. It can also synchronize the system clock with a remote server using the Network Time Protocol (NTP). timedatectl is part of the Systemd system and service manager.

To view all available time zones, use the following command:

timedatectl list-timezones

Screenshot showing the results of the timedatectl list-timezones command.

Since the list is long, you can also use timedatectl list-timezones | grep EST to search for the value EST. Of course, you can change EST to any other zone you’d like to find, for example Paris, as shown below.

Screenshot showing the results of the timedatectl list-timezones | grep Paris command.

Next, use the following command format: sudo timedatectl set-timezone Region/Location , while changing the Region/Location to your desired result.

For example: Africa/Freetown

Screenshot showing the results of the sudo timedatectl set-timezone Region/Location command.

Manually Setting a Date and Time in Linux

To manually set a new date and time in Linux, use the following syntax:

date -s=”Date and time information” as shown below.

date -s “2 June 2023 14:05:00”

Screenshot showing the results of the date -s

Changing a Timezone in Linux

The /etc/localtime is a file that configures the system-wide timezone of the local system that is used by applications. It should be an absolute or relative symbolic link pointing to /usr/share/zoneinfo/, followed by a timezone identifier such as “Europe/Berlin” or “Etc/UTC“.

/usr/share/zoneinfo is a directory that contains files with information about timezones. The files are named after each time zone, such as “America/New_York” or “Europe/London“. These files contain information about the timezone rules and daylight saving time (DST) settings for that timezone.

The contents of /etc/localtime can be found below.

Screenshot showing the contents of the /etc/localtime file.

The contents of /usr/share/zoneinfo can be found below.

Screenshot showing the contents of the /usr/share/zoneinfo file.

To set the timezone of your choice, use the example below which uses Calcutta (IST) for the local time on the system, and replace it with the timezone of your choice.

*NOTE: Creating this link will create a link named “localtime” in whichever directory you are running this command. Any other utility to change the timezone used after will not work as this link will take precedence over anything else. To resolve this, you can remove the link/file “localtime” when it is required.

ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime

Screenshot showing the results of the ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime command.

Looking for more information on Linux ? Search our Knowledge Base !

Читайте также:  Linux дата изменения папки

Interested in more articles about Operating Systems ? Navigate to our Categories page using the bar on the left or check out these popular articles:

Popular tags within this category include: Linux , Windows , Apache , CentOS , Debian , Fedora , RedHat , and more.

Don’t see what you’re looking for? Use the search bar at the top to search our entire Knowledge Base.

The Hivelocity Difference

Seeking a better Dedicated Server solution? In the market for Private Cloud or Colocation services? Check out Hivelocity’s extensive list of products for great deals and offers.

With best-in-class customer service, affordable pricing, a wide-range of fully-customizable options, and a network like no other, Hivelocity is the hosting solution you’ve been waiting for.

Unsure which of our services is best for your particular needs? Call or live chat with one of our sales agents today and see the difference Hivelocity can make for you.

Источник

How To Set or Change Time Zone/Date/Time on Ubuntu

Modern operating systems detect and synchronize time using NIST (National Institute of Standards and Technology) time servers. NIST operates an atomic clock that neither gains nor loses a second in 300 million years.

However, you may find that your system needs to be synchronized with NIST time servers properly.

This guide shows you how to check and change Ubuntu’s time, date, and timezone.

How To Set Time, Date, and TIme Zone on Ubuntu

  • Some operations may require sudo or root privileges
  • The command line/terminal window (Ctrl-Alt-T)

Using timedatectl to Control the System Time and Date

Most modern Linux distributions such as Fedora, Debian, Ubuntu, Arch, CentOS v.7.x+, and other Unix-based systems provide the timedatectl utility. This command allows you to control and edit time and date settings using the command line.

Display Current Date and Time with timedatectl

To display the current time and date information, use the command:

current time and date in Ubuntu

The output provides local time, universal time, and the timezone and informs you if the synchronization process is enabled.

Sync Time to NIST Atomic Clock

Set the Ubuntu system to synchronize to the NIST atomic clock with the following command:

To adjust the time and date manually, turn off NTP synchronizing with:

Note: NTP stands for Network Time Protocol.

How to Change the Time

To set the time to your specifications, use the following command:

timedatectl set-time 21:45:53

The time format is HH:MM:SS (Hours, Minutes, Seconds). Ensure the automatic time synchronization is off to enable changes.

How to Change the Date

Use the same command to define the date on the system:

timedatectl set-time 2019-04-10

The date format is YYYY-MM-DD (Year, Month, and Day).

How to Set a Timezone in Ubuntu

The timedatectl command additionally allows you to synchronize your systems with a time zone of your choosing. To change the time zone, follow the steps below:

1. To list the names of the time zones, use:

timedatectl list-timezones

list of all the timezones available for date and time

2. Find the location closest to you, then enter the following:

timedatectl set-timezone Region/Location

3. Replace Region/Location with a name from the time zone list.

The time zone list is extensive. Filter the list by keyword by piping the grep command:

timedatectl list-timezones | grep keyword

setting time zone using grep

Substitute keyword for any keyword you wish, such as America , Asia , or New_York . If you get an error, double-check your spelling and make sure that you are using capital letters correctly.

Читайте также:  Asus sbw 06d2x u linux

How to Set Universal Time (UTC) in Ubuntu

UTC stands for Coordinated Universal Time and appears in scientific calculations and synchronizing between time zones across the globe. Synchronize your system with the following command:

timedatectl set-timezone UTC

There is no immediate output; however, you can check the applied settings with timedatectl .

Note: GMT and Zulu Time are often used to refer to UTC. They are equivalent terms when fractions of a second are not relevant.

How to Sync Hardware Clock

RTC stands for Real-Time Clock, another name for the hardware clock the computer. The system has a tiny quartz crystal and a battery that keeps time when the system disconnects from a network.

Set Hardware Clock to Sync to Local Timezone

To have the Real-Time Clock synchronize to your local time zone, enter:

timedatectl set-local-rtc 1

You may get an error in this mode, since updating the hardware clock to the local time zone is unsupported.

Set the Hardware Clock to Sync with UTC

Set the hardware clock to synchronize with UTC by entering the following command:

timedatectl set-local-rtc 0

As with the previous command, there is no confirmation that the change has applied. Verify the change manually with the timedatectl command.

Set Time, Date Timezone in Ubuntu Older Versions From Command Line

Older Ubuntu versions may not support the timedatectl command. Find out how to check the Ubuntu version.

There are alternative commands to display and adjust system time setting from a command line. Use the commands listed below:

sudo date -s "YY-MM-DD HH:MM:SS"

Replace YY-MM-DD with Year-Month-Day, and HH:MM:SS with Hour:Minute:Second. You can set just the date or only the time, depending on your needs.

sudo hwclock --show --verbose

Note: Some versions may not support the —verbose option, and it may not work on a virtual machine. The hardware clock may not hold the same time as the operating system.

sudo hwclock --set --date "MM/DD/YY HH:MM:SS"

This command tells the system to set the HC (hardware clock) to SYS (system):

Use this command to reverse the previous process.

This guide showed you how to set the time, date, and time zone on your Ubuntu system. Setting the system to synchronize with NTP is typically the best course of action.

Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.

Your server’s MySQL time zone and your own might be out of sync. Read this article to learn 2 ways of editing .

Finding out which Ubuntu version is running on your system can be important when troubleshooting issues or .

In this tutorial, learn the five most commonly used commands to check memory usage in Linux. We also provide .

You have probably noticed your Linux OS slowing down, especially when working harder. Understanding CPU .

Источник

Оцените статью
Adblock
detector