Linux Date Command __linux

Source: Internet
Author: User
Tags locale set time what date

The function of the date command is to display and set the system date and time.
The general format for this command is: date [options] Displays the time format (beginning with +, followed by formatting)
Date set time format
The meanings of the options in the command are:
-D datestr,--date DATESTR displays the date described by datestr
-S Datestr,--set datestr set datestr description of the date
-U,--universal displays or sets the Universal Time domain
% H hours (00. 23)
% I-hour (01. 12)
% K hours (0. 23)
% l hour (1. 12)
% M minute (00. 59)
% p displays am or PM
% R Time (Hh:mm:ss am or PM), 12 hours
% s number of seconds from January 1, 1970 00:00:00 to current experience
% S sec (00. 59)
% T Time (24-hour system) (HH:MM:SS)
% X shows the format of the time (%h:%m:%s)
% Z time zone Date field
% a weekday abbreviation (Sun.. Sat)
% A week's full name (Sunday). Saturday)
The abbreviation of the% B-month. DEC)
The full name of the% B-month (January). December)
% c date and time (Mon Nov 8 14:12:46 CST 1999)
% d One months of the first day (01. 31)
% D Date (MM/DD/YY)
% h and%b options are the same
% J The first day of the year (001. 366)
% m month (01. 12)
% W one week of the first day (0 for Sunday)
% W The first few weeks of the year (00. 53, Monday for the first day)
% x shows the format of the date (MM/DD/YY)
The last two digits of the Y-year (1999 is 99)
% Y year (for example: 1970,1996 etc.)
Specifically, only Superuser can set the time with the date command, and the average user can only display the time with the date command.

The following environment variables will affect the execution effect of the date command. Data collation LANG determines the default locale that will be used when lc_all and the corresponding environment variable (beginning with lc_) do not specify a locale. Lc_all determines the locale used to overwrite any locale-class values set by LANG or any environment variable beginning with LC_. LC_CTYPE determines the locale in which the byte sequence of the text data is interpreted as a character, such as a single pair of multibyte characters in a parameter. Lc_messages decide which language to use for writing information. Lc_time determines the contents of the date and time string written by date. Nlspath determines the location of the message directory for processing lc_messages. TZ Specifies the time zone to use when and what date, unless you specify the-u option.   If the TZ variable is not set and the-u flag is not specified, the unspecified system default time zone is used. Use example one:

#date//Show Current date

#date-S//Set the current time, only root permission can be set, others can only view.

#date-S 20061010//set to 20061010, this will set the specific time to empty 00:00:00

#date-S 12:23:23//Set the specific time, do not make changes to the date

#date-S "12:12:23 2006-10-10″//so you can set all the time

CST: China Standard Time, which may be Standard for Redhat Linux.

UTC: Coordinated world, also known as World Standard Time, abbreviation UTC, from English international time/French coordination Time "Universal Time/temps cordonné" and come. China, Hong Kong, Macao, Taiwan, Mongolia, Singapore, Malaysia, the Philippines, Western Australia, the time difference between UTC is +8, that is, utc+8.

GMT: Greenwich Mean Time (average Greenwich time or Greenwich Standard Time; English: Greenwich Mean time,gmt) refers to the standard time of the Royal Greenwich Observatory, located in the London suburb of England, because Meridian is defined through the meridians there.

After setting the system time, you also need to sync to the hardware clock
# clock--SYSTOHC

The hardware clock synchronizes with the system clock:

# Hwclock--hctosys
# clock--hctosys

In the above command,--hctosys represents hardware Clock to SYStem Clock.

system clock and Hardware clock sync:

# Hwclock--SYSTOHC
# clock--SYSTOHC

Use Example two:

       Displays the time in the specified format.   $ date & lsquo;+this date is =>%x, the time is now =>%x, thank! '   This is =>11/12/99, the time are now =>17:53:01, thank your!  to display the current times in a predetermined format.   # date  Fri Nov 15:20:18 CST 1999  set time is 14:36 P.M..   # date-s 14:36:00  Fri Nov 14:15:00 CST 1999  set time is November 28, 1999.   # date-s 991128  Sun Nov 00:00:00 CST 1999     set one day ago      Date--date "1 Days ago "+"%y-%m-%d     date command parameter tips   Because Linux has a vague view of man date-d parameters, examples are as follows: # D,--date=string &nbs P;display time described by STRING, not "Now" for Linux [ ~]# date-d n ext-day +%y%m%d 20060328 [Root@li ~]# date-d last-day +%y%m%d 20060326 [ ~]# date-d yesterday +%y%m%d 20060326 [root@linuxso.c Om ~]# date-d tomorrow +%y%m%d 20060328 [ ~]# date-d last-month +%y%m 200602 [ ~]# date-d next-month +%y%m 200604 [ ~]# date-d next-year +%y 2007--------------------------------------- ---and FreeBSD are different, for example: for FreeBSD [ ~]# date-v -1d +%y%m%d 20060326 [ ~]#  date-v- 1m +%y%m%d  20060227 [ ~]#  date-v -1y 20050327 Use example three: a few days ago in a Linux environment just use dat e-d "x days Ago" +%y%m%d x replaced by a number, if you need a few days before the direct write positive, if you want a few days after the date directly to write a negative number; date-d "x weeks Ago" +%y%m%d X is replaced with numbers, if it takes a few weeks before the direct write positive The date directly write negative numbers, date-d "x years ago" +%y%m%d X with a number instead, if you need a few years ago directly write positive numbers, if a few years after the date directly write negative; Look at the following example: [ ~]# Date +%y%m%d 20100107 above is today's date 20100107 [ ~]# date-d "2 days Ago" +%y%m%d          20100105 & nbsp The date above is two days ago [ ~]# date-d ' 4 days ago ' +%y%m%d  20100103 above is four day ago   [ ~]# date-d "-1 days Ago" +%y%m%d 20100108 above is a day after the date [ ~]# date-d "-2 days Ago" +%y%m%d  20100109 above is two day after the date [ro ~]# date-d "1 week Ago" +%y%m%d       20091231 above is the date of a week [ ~]# date-d "1 year ago" +%y%m%d & nbsp   20090107 The date above is a year ago

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.