如何将 TIMEZONE 添加到 VS Code 用户定义片段?

问题描述 投票:0回答:2

看到可用于 VS Code 用户定义片段的时间/日期变量是:

CURRENT_YEAR The current year CURRENT_YEAR_SHORT The current year's last two digits CURRENT_MONTH The month as two digits (example '02') CURRENT_MONTH_NAME The full name of the month (example 'July') CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul') CURRENT_DATE The day of the month as two digits (example '08') CURRENT_DAY_NAME The name of day (example 'Monday') CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon') CURRENT_HOUR The current hour in 24-hour clock format CURRENT_MINUTE The current minute as two digits CURRENT_SECOND The current second as two digits CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch
不幸的是,如果没有 TIMEZONE 或 UTC 的时区偏移,您无法使用这些变量自动创建准确的、时间感知的时间戳。

示例

${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}
评估为:

2022-06-03T07:32:09

,但这不够准确。如果没有 TIMEZONE 标识符,则“时间戳”是“实际时间”的 +/- 23:59:59 反映。

我需要:

2022-06-03T07:32:09-07:00

,我希望时区偏移量根据夏令时调整为 
2022-11-04T07:32:09-08:00

必须是人类可读的。不会使用 Unix 时间。

如何在不启动整个扩展的情况下做到这一点?


编辑 1:非常感谢您合并此功能。太好了,每次创建新时间戳时,在 11 月 5 日及以后,它都会自动显示 -08:00

 而不是 
-07:00
...啊,小胜利!

visual-studio-code timezone timezone-offset vscode-snippets
2个回答

0
投票
事实上,vscode v1.78 中是一个时区偏移变量,请参阅

timezone_offset 的新片段变量

时区偏移的新片段变量

新的代码片段变量

CURRENT_TIMEZONE_OFFSET

 现已可用。
该变量以以下格式返回当前时区偏移量
+HHMM
-HHMM
(例如 
-0700
)。

© www.soinside.com 2019 - 2024. All rights reserved.