我看到可用于 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
...啊,小胜利!
Insert Date String 扩展来处理这个问题。您可以将默认格式定义为 iso,它带有 ctrl-shift-alt-I 按键绑定。效果很好,但我也更喜欢一个片段。
timezone_offset 的新片段变量。
时区偏移的新片段变量新的代码片段变量
CURRENT_TIMEZONE_OFFSET
现已可用。 该变量以以下格式返回当前时区偏移量+HHMM
或-HHMM
(例如-0700
)。