Linux Date Command Detailed

Source: Internet
Author: User

1. Display time

The date command displays dates in the specified format, and only date displays the current time in the default format. As follows:

If you need to display the date in the specified format, you can use a string that begins with "+" to specify its format, in the following format:

%n: Next line
%t: Skip grid
% H: Hours (00-23)
%I: Hours (01-12)
%k: Hours (0-23)
% L: Hours (1-12)
% M: minutes (00-5 9)
%p: Show local AM or PM
%r: Show time directly (12-hour format, Hh:mm:ss [ap]m)
%s: Seconds from January 1, 1970 00:00:00 UTC
% s: Seconds (00-60)
% T: Direct display time (24 hours)
% X: equivalent to%h:%m:%s
%Z: Display time zone
% A: Days of the Week (SUN-SAT)
% A: Day of the Week (Sunday-saturday)
%b: Month (JAN-DEC)
% B: Month (january-december)
%c: Display date and time directly
%d: Day (01-31)
% d: Show date directly (MM/DD/YY)
%h: Same as%b
%j: Day of the Year (001-366)
%m: Month (01-12)
% U: Week of the Year (00-53) (with Sunday as the first day of the week)
%w: Day of the Week (0-6)
% W: Week of the Year (00-53) (in case of Monday as the first day of the week)
%x: Display date directly (MM/DD/YY)
%y: Last two digits of year (00.99)
% y: Full year (0000-9999)

These formats do not have to be remembered, only a few common ones. For example %Y represents the year ,%m represents the month ,%d represents the day ,%H represents the hour ,%m Represents minutes ,%s represents seconds , and%s represents the number of seconds from January 1, 1970 00:00:00 UTC to date, equivalent to the time function , C14>%w represents the day ordinal of a week.

See the example below:

If the time to display is not the current time, but the elapsed time, you can use the- d option. For example, show time three years ago:

See this command I was very hurt, the past time can no longer go back, can only use the command to see. Displays the time after three months:

Show time after 10 days:

Sometimes you need to get the number of seconds that the current time is away from 1970 0:0 0 seconds, stored in the variable:

2. Set the time

Use the- s option to set the system time:

There are a variety of ways to choose from:

You need to believe in the intelligence of date enough.

More places to use:

Use the date command to get the current date and create a new folder based on that date.

Linux Date Command Detailed

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: info-contact@alibabacloud.com 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.