如何在批处理文件(或 msdos)中获取 UTC 时间?而不是系统时间格式

发布于 2024-11-28 23:14:41 字数 88 浏览 3 评论 0原文

如何在批处理文件(或 msdos)中获取 UTC 时间? 这样的系统时间格式

而不是像 dd/MMM/yyyy

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

not like dd/MMM/yyyy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

誰認得朕 2024-12-05 23:14:41

如果不进行自己的日期数学计算,纯批量处理就没有好方法。唯一可用的时间函数是 time /t%time% 并且它们不提供任何位置信息,因此您最终也需要查询注册表。

不过,Powershell 可以做到这一点,您可以编写一个小脚本来获取所需的信息并将其传递到批处理文件中。

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

(来自此处的讨论:http://www.powershellcommunity.org /Forums/tabid/54/aft/4361/Default.aspx

您可以使用 javascript 或 vbs 实现相同的想法。

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.

凉宸 2024-12-05 23:14:41

如果您只想将日期转换为从 1961 年开始的儒略日数(UTC 正式启动时,即 UTC 天 0 时间 00:00:00 是 1961 年 1 月 1 日的第一个时刻),您可以使用这些 Batch文件。

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%

例如:

DATETOUTC %DATE%
18484

参考:http://quasar.as。 utexas.edu/BillInfo/JulianDatesG.html

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

﹎☆浅夏丿初晴 2024-12-05 23:14:41

它很简单,但我用这个:

'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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文