获取其他时区的日期戳(Windows命令行) [英] Get datestamp for a different timezone (Windows command line)

查看:46
本文介绍了获取其他时区的日期戳(Windows命令行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在未来7个小时获取日期戳.

I need to get the datestamp for 7 hrs in the future.

我目前有一个解决方案,但是它需要更改系统日期,这并不理想.有人知道如何在不更改时区的情况下执行此操作吗?

I currently have a solution but it requires changing the system date, which is not ideal. Does anybody know how to do this without changing the time zone?

当前方法(我的时区为PST,亚速尔群岛为+ 7hrs):

Current Method (my time zone is PST and azores is +7hrs):

tzutil /s "Azores Standard Time"

echo %DATE:~-4%%DATE:~4,2%%DATE:~7,2%

tzutil /s "Pacific Standard Time"

推荐答案

使用

This is very easy using getTimeStamp.bat - a hybrid JScript/batch utility that does timestamp computations and formatting The utility is pure script that will run on any modern Windows machine from XP onward - no 3rd party executable required.

完整的文档内置在脚本中.它有很多选择来指定给定的时间戳(或使用当前的本地日期/时间),添加日期和时间偏移,指定时区以及格式化结果.

Full documentation is built into the script. It has oodles of options to specify a given timestamp (or use current local date/time), add date and time offsets, specify time zones, and format the result.

在我看来,您希望日期采用YYYYMMDD格式.假设当前目录中有getTimeStamp.bat,或者更好的是,在路径中的某个位置,那么从命令提示符处发出的以下命令将在未来7小时输出日期:

It looks to me like you want your date to have YYYYMMDD format. Assuming you have getTimeStamp.bat in your current directory, or better yet, somewhere within your path, then the following command issued from the command prompt will print out the date 7 hours in the future:

getTimeStamp -oh +7 -f {yyyy}{mm}{dd}

要在批处理文件中使用它,并将结果存储在 dt 变量

To use it in a batch file and store the result in the dt variable

call getTimeStamp -oh +7 -f {yyyy}{mm}{dd} -r dt

如果您知道所需的时区(相对于GMT而言),则可以指定时区偏移量,而不是与本地时间的偏移量.我相信亚速尔群岛是格林尼治标准时间-60分钟,所以您可以使用:

If you know the time zone you want, relative to GMT, then you can specify the timezone offset instead of the offset from local time. I believe Azores is GMT - 60 min, so you could use:

call getTimeStamp -z -60 -f {yyyy}{mm}{dd} -r dt

这篇关于获取其他时区的日期戳(Windows命令行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆