In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the format and usage of Shell date under Linux". In daily operation, I believe many people have doubts about the format and usage of Shell date under Linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the format and usage of Shell date under Linux". Next, please follow the editor to study!
The common time domains are as follows:
% Y year (for example, 1970, BI, 2018, etc.)% m month (01.12)% d (01.31)% H hour (00.23)% M minute (00.59)% S second (00.59)
Use the date command with no arguments to get the current time and date. The result is usually the time in the CST standard format.
[alvin@VM_0_16_centos ~] $dateSat Nov 3 22:01:57 CST 2018
To get a specific in a specific format, the command is: date + 'format',. Note that this is case-sensitive.
[alvin@VM_0_16_centos ~] $date +'% Y-%m-%d'2018-11-03 [alvin@VM_0_16_centos ~] $date +'% Y/%m/%d% H:%M:%S'2018/11/03 22:08:14
Get yesterday's date. You can add the-d option to the above command.
[alvin@VM_0_16_centos ~] $date-d 'yesterday' +'% Y/%m/%d% H:%M:%S'2018/11/02 22:24:31 or [alvin@VM_0_16_centos ~] $date-d 'today-1 day' +'% Y-%m-%d'2018-11-04
Get an hour before the current time
[alvin@VM_0_16_centos ~] $date-d'today-1 hour' +'% Y%m%d%H'2018110414 or [alvin@VM_0_16_centos ~] $date +'% Y-%m-%d% HV% MV% S'-d'- 1 hours'2018-11-0414: 43:38
Gets the day before the specified date. This is actually asking for relative time. For example, the following asks for the date of the day before the National Day:
[alvin@VM_0_16_centos ~] $date-d '20181001-1 day' +'% Y%m%d'20180930
Convert a date to a timestamp
[alvin@VM_0_16_centos ~] $date-d "Nov 4 15:49:41 CST 2018" +% s1541317781
Convert the timestamp back to the date
[alvin@VM_0_16_centos] $date-d @ 1541317781Sun Nov 4 15:49:41 CST 2018
Convert the timestamp to a date and display it in a specific format
[alvin@VM_0_16_centos ~] $date-d @ 1541317781 +'% Y%m%d% H:%M:%S'20181104 15:49:41, this is the end of the study on the format and usage of Shell dates under Linux. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.