Get date and time in Windows batch

Source: Internet
Author: User

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

Related Article

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.