![]() ![]() If test "' echo $DAY '" = "Aug 16" Then Echo ' Product launch is now two weeks away! ' Fiĭate format conversions in the Unix shell This technique is useful for setting reminders for yourself based on future dates, possibly in a script or Shell startup file, as follows: $ Date-d ' -100 days ' (100 day ago date) $ Date-d ' Dec 14-2 weeks ' (relative: Dec 14 date two weeks ago) You can use negative numbers to get the opposite date: $ Date-d ' day ago ' (30 days before date) Using the AGO directive, you can get past dates: $ date-d next-month +%y%m (next month is a few months) $ date-d last-month +%y%m (last month was a few months) $ date-d last-day +%y%m%d (yesterday's date) or: date-d yesterday +%y%m%d $ date-d next-day +%y%m%d (tomorrow's date) or: Date-d tomorrow +%y%m%d $ Date-d ' next Monday ' (date of next Monday) Using the Next/last directive, you can get what day of the following week: There are some other important ways to use this command. If you are at the Shell prompt, you can get an answer quickly: You can accomplish this task by enclosing this relative offset in quotation marks as an argument to the-D option.įor example, you need to know the date two weeks from now. The D option can also tell you what day of the day is relative to the current date, a number of days or weeks from now, or before (past). So, assuming that a major meeting is held on November 22, you can immediately learn that this day is Wednesday, and that day you will be at the office of the resident. In this example, you can see that this year's November 22 is Wednesday. With this powerful option, you can quickly find out what day of the week a particular date is, by providing a parameter that encloses the date as quotation marks: Know what day of the weekĪnother extension of the GNU to date command is the-D option, which is useful when there are no calendar tables on your desk (UNIX users do not need a calendar table). You can use it to get the day of the week on which the given date is, and to get the relative date corresponding to the current date. ![]() The date tool can do more work than just print out the current system date. ![]() Of course, you can also specify a different NTP server ![]() The NTP service is installed by default on the Linux system, and the NTP synchronization is done manually as follows When you change the system time as root, remember to write the system time to the CMOS in Clock-w, so that the system time will continue to hold the latest correct value the next time you reboot. In addition, only those who get permission (for example, root) can set the system time. Note: When you do not want to appear meaningless 0 o'clock (for example, 7), you can insert-symbol in the tag, for example, date +%-h:%-m:%-s will take away the meaningless 0 in the minutes, as if the original 08:09:04 would become 8:9:4. Show time after hop, then show current date: Date +%t%n%dĭisplay date and set time (12:34:56): Date-date 12:34:56 S DATESTR: Set the system time to the time set in Datestr D datestr: Displays the time set in DATESTR (non-system time) If you do not start with a plus sign, you are setting the time, and the time format is MMDDHHMMYY], %w: The first few weeks of the year (00.53) (in Monday case for day one of the week) %u: The week of the Year (00.53) (with Sunday as the first day of the week) %s: Number of seconds from Janu00:00:00 UTC to date%s: sec (00.61) %r: Direct Display time (12-hour system, format hh:mm:ss m) Usage: Date YY]]ĭescription: Date can be used to display or set the system of dates and times, in the display, users can set the format to display, format set to a plus after a number of tags, where the list of available tags are as follows: The following is a description of some date parameters and some examples Sometimes we need to use dates before or after today, when we can use the date-D parameter # there can be no spaces on either side of the equal sign, before the error has been out hereĮcho "Now time: ' Date ' +%y%m%d%h%m%s '"ĭate1=$ (Date-date= ' 1 days ago +%y%m%d ') #Date of the previous dayĭate1=$ (Date-date= ' 2 days ago +%y%m%d ') #Date of the first two daysĪssign the current date to a date variable ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |