简体   繁体   中英

Windows XP Batch File Date to file name

我目前正在使用以下代码从XP嵌入式计算机返回日期格式,它是XP的相当基本的版本,以下代码在Windows 7计算机(10-02-2015)上返回正确的格式,但在XP上机器返回(星期二)时,如何在不更改机器上XP时间格式的情况下修改代码以返回正确的格式

Set timestamp=%DATE:/=-%

The date format includes the day-of-week at the beginning in many environments - use:

set DT=%DATE:/=-%
set timestamp=%DT:~4%

to set timestamp the way is on your Win7 environment; however, this approach is not exactly portable, just be aware.

EDIT

This will reorder the date and time to something that sorts properly ... and it does happen to also be the order used in Europe:

set DT=%DATE:/=-%
set timestamp=%DT:~10,4%-%DT:~4,5%

keeping in mind, this still isn't portable across systems.

EDIT

Whoop, you wanted UK, which isn't the same as other places - that would be:

set timestamp=%DT:~7,3%%DT:~4,3%%DT:~10,4%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM