How to Set Date, Time and Timezone in Linux

How to set date, time and timezone on Linux/Unix box will be introduced in this post.

Unix time, or POSIX time which is a system for describing points in time is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.

The number of seconds elapsed can be got by this command on Linux/Unix systems:

$ date +%s

Set Linux date

Linux date can be set using following syntax:

# date +%Y%m%d -s "yyyymmdd"

yyyy is year, mm is month and dd is day.

For example, we can set the date to June 22, 2010 by:

# date +%Y%m%d -s "20100622"

Set Linux time

Linux time can be set using following syntax:

# date +%T -s "hh:mm:ss"

hh is hour, mm is minite and ss is second.

For example, we can set the time to 11:28 by:

# date +%T -s "11:28:00"

Set Linux date and time

The date and time can be set by date command at the same time by:

# date mmddhhmmyyyy.ss

The first mm means month while the second mm means minite.

For example, we can set the date and time to 11:28 on June 22, 2010 by:

# date 062211282010.00

Another way to set new date and time is using the following syntax:

# date --set="STRING"

The method to set the date and time above is:

# date -s "22 JUN 2010 11:28:00" 

or

# date --set="22 JUN 2010 11:28:00" 

Set Linux timezone

The configuration file for timezone is usally /etc/localtime which is often a symlink to the file localtime or to the correct time zone file in the system. The time zone directory is /usr/share/zoneinfo where you can find a list of time zone regions. In some distro such as Fedora/RHEL/Cent OS, the zone files use /usr/share/zoneinfo/REGION/CITY like format.

The method for setting Linux timezone:

Backup old timezone info if needed

# mv /etc/localtime /etc/localtime.bak

Find out the appropriate timezone from /etc/localtime and create a symbolic link to it

For example we want to set the time zone to Hong Kong time:

# ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

Verify the timezone is changed

$ date

You may get a output like this:

$ date
Tue Jun 22 12:33:10 HKT 2010

Some related utilities

Here is some related Linux time/date related utilities.

Update the current system time by rdate

# rdate -s time.nist.gov

For a list of available time servers, please check NIST Internet Time Servers.

Set the hardware clock

# /sbin/hwclock --systohc

Fedora/RHEL/CentOS have a date/time setting tool

You can use the GUI tool on Red Hat’s distros:

# system-config-date

Or try:

# setup 

and then select the timezone entry.

Similar Posts

  • How to find a wireless network adapter’s speed in Linux?

    How to find a wireless adapter‘s speed in Linux? ethtool does not show the speed of the wireless adapters. For finding the configured speed of wireless adpaters in Linux, you can use the iwconfig tool. iwconfig: configure a wireless network interface For example, to find the speed of the wireless adapter wlp8s0: # iwconfig wlp8s0…

  • How to install Chrome on Fedora Linux?

    How to install the Chrome browser on Fedora Linux from Google? Google provides a repository for yum/dnf on Fedora. First, following http://www.systutorials.com/3471/additional-repositories-for-fedora-linux/#google-chrome-repository to add Google Chrome repository. Then, you can install Google Chrome by yum/dnf: # dnf install google-chrome-stable Read more: How to install JRE for Chrome on Linux x86-64 Chrome’s KDE proxy integration broken…

  • |

    SmIley faces in iPhone

    How to input smiley faces in iPhone? I use Emoji Free app to enable the Emoji input methods. It is quite good and enables inputing of many nice smiley faces and icons. The app from App Store: Emoji Free app. Read more: Changing iPhone Holiday Calendar to Your Local One How to Play YouTube Video in…

  • How to filter bbpress content in WordPress

    In WordPress, we can filter the post content by adding a filter to the_content: add_filter('the_content', 'inline_markdown_pre_process_shortcode2', 7); But how to filter the content for bbpress contents? bbpress topic and reply (they are separated) content have their own filters: bbp_get_topic_content and bbp_get_reply_content. For example, add_filter(‘bbp_get_topic_content’, ‘my_plugin_custom_bbp_function’); add_filter(‘bbp_get_reply_content’, ‘my_plugin_custom_bbp_function’); function my_plugin_custom_bbp_function($content) { return ‘my_plugin_custom_bbp_function processed: ‘.$content; }…

  • Xen HVM DomU configuration file

    An example of Xen HVM DomU configuration file. An example for install the OS from an ISO: name=”10.0.1.235″ vcpus=2 memory=2048 shadow_memory=8 disk=[‘file:/lhome/xen/vm-10.0.1.235/vmdisk0,xvda,w’, ‘file:/lhome/Linux-x86_64-DVD.iso,xvdc:cdrom,r’] vif=[‘bridge=xenbr0′] kernel=’/usr/lib/xen/boot/hvmloader’ builder=’hvm’ device_model=’/usr/lib64/xen/bin/qemu-dm’ extra=” vnc=1 vnclisten=”0.0.0.0″ vncpasswd=’1234567′ # vncdisplay=1 vncconsole=1 on_reboot=’restart’ on_crash=’restart’ An example for run the VM after installation: name=”10.0.1.235″ vcpus=2 memory=2048 shadow_memory=8 disk=[‘file:/lhome/xen/vm-10.0.1.235/vmdisk0,xvda,w’] vif=[‘bridge=xenbr0′] kernel=’/usr/lib/xen/boot/hvmloader’ builder=’hvm’ device_model=’/usr/lib64/xen/bin/qemu-dm’ extra=” vnc=1…

Leave a Reply

Your email address will not be published. Required fields are marked *