Dos Date and Time format setting Summary (Date and Time)

Source: Internet
Author: User

Copy codeThe Code is as follows: @ echo off
@ Edit and test the title string (the arrows → ← described below indicate the right and left respectively)
Set aa = 1234567890
Echo Description: In the composite variables below, the number before the comma represents the pointer offset, and the number after the comma represents the extracted character length.
Echo % aa :~ // Pointer to the right → offset 1 bit, then start from the pointer to the right → extract 5 characters.
Echo % aa :~ 0,-3% // the pointer is not offset, → extract all characters and remove the last three characters.
Echo % aa :~ 5% // a single number with no length value specified. It indicates pointer → offset of 5 characters, and then, → extract all characters.
Echo % aa :~ -5% // a single negative value. In special cases, this parameter indicates the reverse direction offset of the pointer. Starting from the rightmost end, the cursor value is 5 bits and starting from the pointer → all characters are extracted. it can also be simply interpreted as extracting 5 characters at the end of a string.

The echo pointer is offset from the rightmost end of the string from the right to the left.

Echo % aa :~ -// The offset value is negative, indicating that the pointer is shifted from the rightmost end to the left direction by two digits, and then starts from the pointer to the right → extracts 1 character to generate a new variable value. note the space at the end of the string, because the space will also be extracted to the variable as a "Transparent Character". Remember to remove the space at the end of the variable. ctrl + A to quickly and conveniently check whether the variable string end contains spaces.
Echo % aa :~ -4,3% // start from the rightmost end. The pointer must be 4 bits and then → extract 3 characters.
Echo % aa :~ -4,-2% // starting from the rightmost end, the pointer cursor is offset by four digits, and then starts from the pointer. → extract all characters and remove the last two characters.

Echo Application
Echo % date :~ 0, 10% // extract year, month, and day Information
Echo % date :~ -3% // extract the day of the week
Echo % time :~ // Extract time and minute in time
Echo % time :~ 0,-3% // extract time and minute and second Information
Pause

Summary:
1. When the offset is a positive value, the pointer moves to the right. If the offset is a negative value, the pointer moves from the rightmost end of the string to the left.
2. If the length value is positive, it indicates to extract several characters to the right. If it is negative, it indicates to extract all characters to the right and remove several characters. "Several = the absolute value of the length value. "The direction of extracted characters is always from left to right.
3. If it is a single number, this number indicates the offset. The default value of the length value is the "remainder" of the string, that is, all characters starting from the pointer and going to the right. if the number is a negative number, it can be simply understood as: extract several characters at the end of the string. (the correct explanation should be: indicates the reverse direction offset of the pointer, starting from the rightmost end, starting from the nth position, and then starting from the pointer → extracting all characters)
■ % Date % and % time % are built-in date and time variables.

Set date = % Date :~ 0, 4% % Date :~ 5, 2% % Date :~ 8, 2% % Time :~ 0, 2% % Time :~ 3,2% % Time :~ 6, 2%
% Date :~ 0, 4% indicates year, and so on
Display format: 20120515105610

DOS date format settings

% Date % and % time %
21:34:11. 56
C: \> echo % date %
Tuesday

C: \> echo % date :~ 0, 4%
2008

Drive letter: \> output % date % is a parameter, but the values following it are the value range. The first 0 in the following value indicates that 4 in the beginning indicates that a total of four characters are taken.

C: \> echo % date :~ -3%
Wednesday
The negative number indicates the reciprocal, which is the last three characters.
C: \> echo % date :~ -3,-1%.
Week
Here-1 is not to output the last 1 character-2 is of course 2 and so on

Time is similar.

Echo % time %

21:34:11. 56

Doscommand Date and Time

I. DATA Date setting command

Function: set or display the system date.
Type: Internal commands
Format: Date [mm-dd-yy]
Instructions for use:
(1) omit [mm-dd-yy] to display the system date and prompt to enter a new date. If you do not modify the date, press the Enter key directly, [mm-dd-yy] is in the format of "month, month, day, day, and year;
(2) When the machine starts to start and an automatic processing file (AUTOEXEC. BAT) is executed, the system does not prompt to enter the system date. Otherwise, the system prompts you to enter a new date and time.
Instance:
View the date of the current system. Enter date directly.
  
Ii. TIME system clock setting command

Function: set or display the system period.
Type: Internal commands
Format: TIME [hh: mm: ss: xx]
Instructions for use:
(1) If [hh: mm: ss: xx] is omitted, the system time is displayed and a new time is prompted. If you do not change the time, press the Enter key directly. [hh: mm: ss: xx] is in the format of "hour: minute: Second: percent seconds;
(2) When the machine starts to start and an automatic processing file (AUTOEXEC. BAT) is executed, the system does not prompt to enter the system date. Otherwise, the system prompts you to enter a new date and time.

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.