It is important to use the date and time as the file name when writing Windows batch processing.
How do I get the date?
Format:%date%
Results: 2012-07-31
How to get the time?
Format:%time%
Results: 10:21:21.68
This is the date and time to get the system standard format, but sometimes we need to use the prescribed format, what to do?
Format:%date:~x,y% and%time:~x,y%
Description: X is the start position, Y is the number of characters acquired
For example, I want to get the full date and time,
Format:%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
Results: 20120731111039
But if the time is earlier than 10 o'clock, then only show the date does not show the time, such as: 20120731, how to solve it?
Format:%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%
Results: 20120731052539
This will achieve our goal, the success of the date and time.
This article is from "learning." "Blog, be sure to keep this provenance http://aixer95.blog.51cto.com/943421/1672645
Get date and time in Windows batch