How do I get the day month and year from a Windows cmd.exe script?

前端 未结 14 1392
长情又很酷
长情又很酷 2020-12-23 17:02

How do I get the current day month and year from inside a Windows cmd script? I need to get each value into a separate variable.

14条回答
  •  滥情空心
    2020-12-23 17:06

    To get the year, month, and day you can use the %date% environment variable and the :~ operator. %date% expands to something like Thu 08/12/2010 and :~ allows you to pick up specific characters out of a variable:

    set year=%date:~10,4%
    set month=%date:~4,2%
    set day=%date:~7,2%
    set filename=%year%_%month%_%day%
    

    Use %time% in similar fashion to get what you need from the current time.

    set /? will give you more information on using special operators with variables.

提交回复
热议问题