Batch file 我可以用RFC 3339格式获取当前日期吗?

Batch file 我可以用RFC 3339格式获取当前日期吗?,batch-file,mercurial,cmd,Batch File,Mercurial,Cmd,我正在编写一个批处理脚本(cmd),其中以RFC3339格式获取变更集的日期: FOR /F "usebackq delims=" %%G IN ^ (`hg log -r . --cwd "%~dp0" --template "{date|rfc3339date}"`) ^ do SET hg_changeset_date_rfc3339=%%G echo %hg_changeset_date_rfc3339% <------ writes "2009-08-18T1

我正在编写一个批处理脚本(cmd),其中以RFC3339格式获取变更集的日期:

FOR /F "usebackq delims=" %%G IN ^
  (`hg log -r . --cwd "%~dp0" --template "{date|rfc3339date}"`) ^
  do SET hg_changeset_date_rfc3339=%%G
echo %hg_changeset_date_rfc3339%       <------ writes "2009-08-18T13:00:13+02:00"
FOR/F“usebackq delims=“%%G IN^
(`hg log-r。--cwd“%~dp0”--模板“{date | rfc3339date}`)^
是否设置hg\u变更集\u日期\u rfc3339=%%G

echo%hg\u changeset\u date\u rfc3339%您可以使用
wmic
命令获取当前日期和时间,而不受区域设置的影响

@echo off
SETLOCAL EnableDelayedExpansion


for /f "skip=1 tokens=1-6 delims= " %%a in ('wmic path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do (
    IF NOT "%%~f"=="" (
        set /a FormattedDate=10000 * %%f + 100 * %%d + %%a
        set FormattedDate=!FormattedDate:~0,4!-!FormattedDate:~-4,2!-!FormattedDate:~-2,2!
        set /a FormattedTime=%%b * 10000 + %%c * 100 + %%e
        set FormattedTime=!FormattedTime:~0,2!:!FormattedTime:~-4,2!:!FormattedTime:~-2,2!
    )
)

echo !FormattedDate!T!FormattedTime!Z <--Assuming UTC timezone is used
PAUSE

希望有帮助:)

您能够/允许运行powershell吗?@Kayasax:应该可以,但这需要重写整个脚本吗?可能是@Benoit的副本否,您应该能够从cmd(powerhsell.exe-文件c:\psscript.ps1)中调用powershell脚本,以ps1格式将日期设置为合适的格式,并将其导出到文件中,然后从cmd获取文件内容。在这里查看powershell日期格式:可能您正在寻找类似的东西,您可以在周围放置一个包装器来调用它。如果我需要删除2小时,例如,因为我在时区+2,该怎么办?
C:\>dateTime.bat
2013-01-25T22:11:40Z
Press any key to continue...