In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use the date command in Linux, I believe many inexperienced people are helpless about this, for this reason this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.
purpose description
The date command can be used to display and modify the system date and time, note that it is not the time command.
common parameters
Format: Date
Displays the current date and time.
Format: mmddHHMM #In short, it is "month day"
Format: mmdddate HHMMYYYY
Format: mmdddate HHMM.SS
Format: mmdddate HHMMY.SS
Set the current date and time, only root user can execute, after execution, execute clock -w to synchronize to the hardware clock.
mm is the month, dd is the date, HH is the hour, MM is the minute, YYYY is the year, SS is the second.
Format: date +FORMAT
Displays the current time according to the specified format. For example, date +%Y-%m-%d displays the current date in the form of Y-mm-dd, where YYYY is the year, mm is the month, and dd is the date.
Common FORMAT
The code is as follows:
Year in %Y YYY format
Month in %m mm format (), 01-12
Date in dd format (day of month), 01-31
%H Hours in HH format (), 00-23
Minutes in %M MM format (), 00-59
%S SS format seconds (), 00-59
%F Full date in Y-mm-dd format as %Y-%m-%d
Time in %T HH-MM-SS format as %H:%M:%S
%s Number of seconds since 1970. C function time(&t) or Java System.currentTimeMillis()/1000, new Date().getTime()/1000
%w Day of the week, 0-6, 0 for Sunday
%u Day of the week, 1-7, 7 means Sunday
Note that the above formats can be combined arbitrarily, and can also include unformatted strings, such as date "+ today is %Y-%d-%m, now it is $H:%M:%S"
More formats man date or info date
Format: date -d STRING
Format: date-date=STRING
Format: date -d STRING +FORMAT
Display time described by STRING, not 'now'.
Format: date -s STRING
Format: date-set=STRING
Sets the current time to the datetime specified by STRING.
STRING can be varied and supports many ways of describing dates and times. Here are some common ways to express dates, hoping to draw inferences from one instance.
Date specified:
date -d YYYY-mm-dd
Specify time, date is today:
date -d HH:MM:SS
Specify Date Time:
date -d "YYYY-mm-dd HH:MM:SS"
Specify the number of seconds since 1970:
date -d '1970-01-01 1251734400 sec utc'(Tuesday September 1, 2009 00:00:00 CST)
date -d '1970-01-01 1314177812 sec utc'(Wednesday, August 24, 2011 17:23:32 CST)
Today:
date
date -d today
date -d now
Tomorrow:
date -d tomorrow
date -d next-day
date -d next-days
date -d "next day"
date -d "next days"
date -d "+1 day"
date -d "+1 days"
date -d "1 day"
date -d "1 days"
date -d "-1 day ago"
date -d "-1 days ago"
Yesterday:
date -d yesterday
date -d last-day
date -d last-days
date -d "last day"
date -d "last days"
date -d "-1 day"
date -d "-1 days"
date -d "1 day ago"
date -d "1 days ago"
The day before yesterday:
date -d "2 day ago"
date -d "2 days ago"
date -d "-2 day"
date -d "-2 days"
The day before yesterday:
date -d "3 day ago"
date -d "3 days ago"
date -d "-3 day"
date -d "-3 days"
Last week, a week ago:
date -d "1 week ago"
date -d "1 weeks ago"
Last Friday (not last Friday):
date -d "last-friday"
date -d "last friday"
Last month, January ago:
date -d last-month
date -d last-months
date -d "-1 month"
date -d "-1 months"
Next month, after January:
date -d next-month
date -d next-months
date -d "+1 month"
date -d "+1 months"
Last year, a year ago:
date -d last-year
date -d last-years
date -d "-1 year"
date -d "-1 years"
Next year, a year later:
date -d next-year
date -d next-years
date -d "+1 year"
date -d "+1 years"
An hour ago:
date -d "last-hour"
date -d "last-hours"
date -d "1 hour ago"
date -d "1 hours ago"
An hour later:
date -d "1 hour"
date -d "1 hours"
A minute ago:
date -d "1 minute ago"
date -d "1 minutes ago"
One minute later:
date -d "1 minute"
date -d "1 minutes"
One second ago:
date -d "1 second ago"
date -d "1 seconds ago"
One second later:
date -d "1 second"
date -d "1 seconds"
uses examples
Example 1 Display and Set Date Time
The code is as follows:
[root@node56 ct08]# date
Saturday August 20th, 2011 17:37:11 CST
[root@node56 ct08]# date 08220942
Monday August 22nd, 2011 09:42:00 CST
[root@node56 ct08]# clock -w
[root@node56 ct08]# date
Monday August 22nd, 2011 09:42:01 CST
[root@node56 ct08]#
Example 2 shows the specified date and time
The code is as follows:
[root@node56 ~]# date
Tuesday August 23rd, 2011 07:41:03 CST
[root@node56 ~]# date -d next-day +%Y%m%d
20110824
[root@node56 ~]# date -d next-day +%F
2011-08-24
[root@node56 ~]# date -d next-day ‘+%F %T’
2011-08-24 07:41:47
[root@node56 ~]# date -d last-day ‘+%F %T’
2011-08-22 07:43:46
[root@node56 ~]#
[root@node56 ~]# date -d yesterday ‘+%F %T’
2011-08-22 07:44:31
[root@node56 ~]# date -d tomorrow ‘+%F %T’
2011-08-24 07:45:19
[root@node56 ~]# date -d last-month +%Y%m
201107
[root@node56 ~]# date -d next-month +%Y%m
201109
[root@node56 ~]# date -d next-year +%Y
2012
[root@node56 ~]#
After reading the above, do you know how to use the date command in Linux? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.