In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the date command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Linux common command date command can be used to set and display the current time of the system, especially in some Shell commands in which the date command is used to display different dates, so this command is also a command that needs to be mastered.
Date displays or sets the system time and date
Summary date [OPTION]... [+ FORMAT] date [- u |-- utc |-- universal] [MMDDhhmm [[CC] YY] [.ss]] main purpose conversion time to the selected format. Default is current.
Set the system time.
Parameter format: the time format of the output.
The escape sequence available for format is as follows:% sign% a locally abbreviated working day name (e.g., Sun)% A local full working day name (e.g., Sunday)% b locally abbreviated month name (e.g., Jan)% B locally complete month name (e.g., January)% c local date and time (e.g. Thu Mar 3 23:05:25 2005)% C Century, similar to% Y, but omitting the last two digits (for example, 20)% d one day in January (for example, 01)% D date, equivalent to a day in% m/%d/%y% e month, formatted with spaces, equivalent to% d% F complete date The year of the last two digits of% G ISO standard count week equivalent to% + 4Y-%m-%d% g ISO standard count week, usually only useful for% V% h is equivalent to% b% H hour, range (00.23)% I hour, range (00.23)% j one day of the year, range (001.366)% k hour Filled with spaces, range (0.23), equivalent to% _ H% l hours, filled with spaces, range (1... 12), equivalent to% _ I% m months, range (01.. 12)% M minutes, range (00.59)% n newline character% N nanosecond, range (000000000.000000000)% p is used to represent local AM or PM Blank if unknown% P is similar to% p, but in lowercase% Q quarter, range (1.. 4)% r Local clock time in 12 hours (for example, 11:11:04 PM)% R 24 hours per minute Equivalent to% Hpurs% M% s since 00:00 UTC on January 1, 1970, range (000.60)% t horizontal tab% T time Equivalent to% H:%M:%S% u one day of the week (1... 7), 1 represents the week ordinal of Monday% U, and Sunday serves as the beginning of the week (00... 53)% V ISO standard counting week. This method takes Monday as the beginning of the week (01... 53)% w one day of the week (0... 6). 0 represents the week ordinal of Sunday% W, Monday as the beginning of the week (00.53)% x the local date (e.g., 12-31-99)% X the local time represents (e.g., 23:13:48) the last two digits of% y year, the range (00.99)% Y year% z + hhmm numeric time zone format (e.g. -0400)%: numerical time zone format of z + hh:mm format (e.g.,-04:00)%:: Z + hh:mm:ss numerical time zone format (e.g.,-04:00:00)%:: Z numerical time zone format, adding': 'compared to the previous format':'to show the necessary precision (for example,-04 camera 05EDT 30)% Z time zone abbreviation (e.g. EDT) by default Date populates the number field with zero The following optional symbols can be followed by'%':-(hyphen) do not fill in the corresponding fields. _ (underscore) fill in the corresponding fields with spaces. 0 (number 0) populates the corresponding field with the number 0. + is filled with the number 0, and the number greater than 4 digits in the future year is preceded by a'+ 'sign. Use uppercase if allowed. If allowed, convert the default uppercase to lowercase and the default lowercase to uppercase. Any flag is followed by an optional field width, such as a decimal, followed by an optional modifier, where available, using E to use an alternative representation of the locale and O to use an alternative numeric symbol of the locale. The long option is equivalent to the short option-d,-- date=STRING parses the string and outputs it in the specified format. The string cannot be 'now'. -- debug comments parsed dates and sends questionable usage to standard error. -f,-- file=DATEFILE is similar to-- date; processes one line at a time from DATEFILE. -I [FMT],-- iso-8601 [= FMT] is output in ISO 8601 format, and FMT can be 'date' (default),' hours','minutes','seconds','ns'. For example: 2006-08-14T02:34:56-06:00-R,-- rfc-email output in RFC 5322 format, for example: Mon, 14 Aug 2006 02:34:56-0600-rfc-3339=FMT output in RFC 3339 format, FMT can be one of 'date',' seconds','ns' For example: 2006-08-14 02:34:56-06:00-r,-- reference=FILE shows when the file was last modified. -s,-- set=STRING sets the system time according to the string. -u,-- utc,-- universal displays or sets Universal coordinated time (UTC). -- help displays help information and exits. -- version displays version information and exits. The return status of the return value is successful unless an illegal option or parameter is given.
Example # formatted output: date + "% Y-%m-%d" 2009-12-07 # output yesterday date: date-d "1 day ago" + "% Y-%m-%d" 2012-11-19 # 2 seconds later output: date-d "2 second" + "% Y-%m-%d% H:%M.%S" 2012-11-20 1234567890 seconds in the legend: date-d 1970-01-01 1234567890 seconds "+"% Y-%m-%d% H:%M:%S "# or date-dang 1234567890 +"% F% T "# output result 2009-02-13 23:02:30 # time format conversion: date-d" 2009-12-12 "+"% Y/%m/%d% H:%M.%S "# output result 2009-12-12 00H:%M:%S 00.00 # apache format conversion: date-d" Dec 5 2009 12:00:37 AM "+"% Y-%m-%d% H:%M.%S "# output result 2009-12-05 00 H:%M.%S 00.37 # time Walk after format conversion: date-d" Dec 5 2009 12:00:37 AM 2 year ago "+"% Y-%m-%d% H:%M.%S "# output result 2007-12-05 00Y-%m-%d 00.37 # time addition and subtraction operation: date +% Y%m%d # shows date-d" + 1 day "+% Y%m%d # shows the date of the previous day date-d"-1 day "+% Y% M% d # shows the date of the previous day date-d "- 1 month" +% Y%m%d # shows the date of the previous month date-d "+ 1 month" +% Y%m%d # shows the date of the next month date-d "- 1 year" +% Y%m%d # shows the date of the previous year date-d "+ 1 year" +% Y%m%d # shows the next Date # set time: date-s # set the current time Only root permission can be set. Others can only view date-s 20120523 # set to 20120523. This will set the specific time to 00:00:00 date-s 01:01:01 # set the specific time Do not change the date date-s "01:01:01 2012-05-23" # so you can set all time date-s "01:01:01 20120523" # so you can set all time date-s "2012-05-23 01:01:01" # so you can set all time date-s "20120523 01:01:01" # so you can set all time # Sometimes it is necessary to check the time spent by a set of commands: start=$ (date +% s) nmap wangchujiang.com & > / dev/null end=$ (date +% s) difference=$ ((end-start)) # shows the execution time echo $difference seconds. # when you consider outputting a string with a time, for example (Current time: 2019-05-19): # commonly used method: echo "Current time: $(date +"% Y/%m/%d ")" # another method: suffix='Current time:' # Note that variables cannot be replaced by single quotation marks. Date + "${suffix}% Y/%m/%d" Note this command is a command in the GNU coreutils package. For help, please see man-s 1 date or info coreutils' date invocation'.
Thank you for reading this article carefully. I hope the article "how to use date commands in Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!
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.