[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[日期时间] 批处理世界时转换求助

我现在通过
  1. @echo off
  2. >%tmp%\tmp.vbs echo wscript.echo DateAdd ("h",-8,Now())
  3. for /f "delims=" %%a in ('cscript //nologo %tmp%\tmp.vbs') do set newtime=%%a&&del %tmp%\tmp.vbs
  4. echo %newtime%
  5. pause
复制代码
这个脚本可以把系统时间转换成世界时,但是发现转换完成的世界时,格式输出的时候,月日时缺位均不补0,请教一下,这个补0应该怎么个写法呢,万分感谢

  1. @echo off
  2. >%tmp%\tmp.vbs echo,NewDateTime = DateAdd("h",-8,Now())
  3. >>%tmp%\tmp.vbs echo,FmtDateTime = Year(NewDateTime)^&Chr(45)^&Right("0"^&Month(NewDateTime),2)^&Chr(45)^&Right("0"^&Day(NewDateTime),2)^&Chr(32)^&Right("0"^&Hour(NewDateTime),2)^&Chr(58)^&Right("0"^&Minute(NewDateTime),2)^&Chr(58)^&Right("0"^&Second(NewDateTime),2)
  4. >>%tmp%\tmp.vbs echo,wscript.echo FmtDateTime
  5. for /f "delims=" %%a in ('cscript //nologo %tmp%\tmp.vbs') do set newtime=%%a
  6. echo %newtime%
  7. pause
复制代码

TOP

  1. @echo off
  2. >%tmp%\tmp.vbs echo wscript.echo DateAdd ("h",-8,Now())
  3. for /f "tokens=1-3 delims=-\/ " %%a in ('cscript //nologo %tmp%\tmp.vbs') do (
  4. set /a "newtime=%%a * 10000+10%%b %% 100 * 100 + 10%%c %% 100"
  5. del %tmp%\tmp.vbs
  6. )
  7. echo %newtime%
  8. pause
复制代码

TOP

本帖最后由 apang 于 2015-4-16 21:18 编辑
  1. @echo off
  2. (for /f %%a in ('wmic os get CurrentTimeZone^|findstr [0-9]') do (
  3.         echo,Set dt=CreateObject("WbemScripting.SWbemDateTime"^)
  4.         echo,dt.SetVarDate DateAdd("n",-%%a,Now^), true
  5.         echo,WScript.Echo dt.Value
  6. ))>$
  7. for /f "delims=." %%a in ('cscript -nologo -e:vbs $') do set "d=%%a"
  8. echo,%d:~,4%-%d:~4,2%-%d:~6,2% %d:~8,2%:%d:~10,2%:%d:~-2%
  9. pause
复制代码

TOP

一段完整的获取世界时的代码,完全批处理,不需其他脚本支持,拿走不谢~~

set td=%date:~2,2%%date:~5,2%%date:~8,2%
set dy=%date:~0,4%
set dm=%date:~5,2%
set dd=%date:~8,2%
set da=%date:~8,2%
if %dm%%dd%==0101 goto L01
if %dm%%dd%==0201 goto L02
if %dm%%dd%==0301 goto L07
if %dm%%dd%==0401 goto L02
if %dm%%dd%==0501 goto L04
if %dm%%dd%==0601 goto L02
if %dm%%dd%==0701 goto L04
if %dm%%dd%==0801 goto L02
if %dm%%dd%==0901 goto L02
if %dm%%dd%==1001 goto L05
if %dm%%dd%==1101 goto L03
if %dm%%dd%==1201 goto L06
if %dd%==02 goto L10
if %dd%==03 goto L10
if %dd%==04 goto L10
if %dd%==05 goto L10
if %dd%==06 goto L10
if %dd%==07 goto L10
if %dd%==08 goto L10
if %dd%==09 goto L10
if %dd%==10 goto L11
set /A dd=dd-1
set dt=%dy%-%dm%-%dd%
goto END
10
set /A dd=%dd:~1,1%-1
set dt=%dy%-%dm%-0%dd%
goto END
:L11
set dt=%dy%-%dm%-09
goto END
:L02
set /A dm=%dm:~1,1%-1
set dt=%dy%-0%dm%-31
goto END
:L04
set /A dm=dm-1
set dt=%dy%-0%dm%-30
goto END
:L05
set dt=%dy%-09-30
goto END
:L03
set dt=%dy%-10-31
goto END
:L06
set dt=%dy%-11-30
goto END
:L01
set /A dy=dy-1
set dt=%dy%-12-31
goto END
:L07
set /A "dd=dy%%4"
if not %dd%==0 goto L08
set /A "dd=dy%%100"
if not %dd%==0 goto L09
set /A "dd=dy%%400"
if %dd%==0 goto L09
:L08
set dt=%dy%-02-28
goto END
:L09
set dt=%dy%-02-29
goto END
:END
set yt=%dt:~0,4%%dt:~5,2%%dt:~8,2%
set td2=%date:~0,4%%date:~5,2%%date:~8,2%

set nt=%time:~0,2%  
if %nt% lss 8 goto L12

set /a nt1=%nt%-8
echo %nt1%

if %nt1% lss 10 goto L13
echo sjs=%td2%%nt1%
goto END2


:L13
echo sjs=%td2%0%nt1%
goto END2


:L12
set /a nt1=%nt%+24-8
echo %nt1%
echo sjs=%yt%%nt1%
:END2

TOP

返回列表