开发者

how do i get UTC time in batch file (or msdos) ? instead of systems time format

how to i get UTC time in batch file (开发者_JAVA技巧or msdos)? instead of systems time format

not like dd/MMM/yyyy


Without doing your own date math, there isn't a good way in pure batch. The only time function available is time /t or %time% and they don't give any locality information, so you'd end up needing to query the registry, too.

Powershell can do it, though, and you can write a tiny script to get the info you want and pass it out to your batchfile.

Get-Date -date (Get-Date).ToUniversalTime()-uformat %y%m%d%H%M%j

(from a discussion here: http://www.powershellcommunity.org/Forums/tabid/54/aft/4361/Default.aspx)

You could do the same idea with javascript or vbs.


If you just want to convert a date to its Julian Day Number starting at 1961 (when UTC was officially initiated, that is, UTC day 0 time 00:00:00 was the first instant of 1 January 1961), you may use these Batch files.

DATETOJULIAN.BAT:

@ECHO OFF
REM GET MONTH, DAY, YEAR VALUES
FOR /F "TOKENS=1-3 DELIMS=/" %%A IN ("%1") DO SET MM=%%A& SET DD=%%B& SET YY=%%C
REM ELIMINATE LEFT ZEROS
SET /A DD=10%DD% %% 100, MM=10%MM% %% 100
REM CALCULATE JULIAN DAY NUMBER
IF %MM% LSS 3 SET /A MM+=12, YY-=1
SET /A A=YY/100, B=A/4, C=2-A+B, E=36525*(YY+4716)/100, F=306*(MM+1)/10, JDN=C+DD+E+F-1524

DATETOUTC.BAT:

@ECHO OFF
CALL DATETOJULIAN %1
SET UTCDAY=%JDN%
CALL DATETOJULIAN 1/1/1961
SET /A UTCDAY-=JDN
ECHO %UTCDAY%

For example:

DATETOUTC %DATE%
18484

Reference: http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html


Its simple but I use this:

'Create a string to be used for file name that is the current date time stamp
dtmYear = Year(Date)

dtmMonth = Month(Date)
If Len(dtmMonth) = 1 Then dtmMonth = "0" & dtmMonth

dtmDay = Day(Date)
If Len(dtmDay) = 1 Then dtmDay = "0" & dtmDay

dtmHour = Hour(Now)
If Len(dtmHour) = 1 Then dtmHour = "0" & dtmHour

dtmMinute = Minute(Now)
If Len(dtmMinute) = 1 Then dtmMinute = "0" & dtmMinute

dtmSecond = Second(Now)
If Len(dtmSecond) = 1 Then dtmSecond = "0" & dtmSecond

strUTCDate = dtmYear & dtmMonth & dtmDay & dtmHour & dtmMinute & dtmSecond
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜