Reputation: 4405
I see the time/date variables available to VS Code User Defined Snippets are:
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
Unfortunately, without TIMEZONE or TIMEZONE OFFSET from UTC, you can't automatically create an accurate, time-aware timestamp using these variables.
Example:
${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}
Evaluates to: 2022-06-03T07:32:09
, but thats not accurate enough. Without a TIMEZONE identifier, that "timestamp" is +/- 23:59:59 reflection of "actual time".
I need:
2022-06-03T07:32:09-07:00
and I want the timezone offset to adjust for daylight savings time to 2022-11-04T07:32:09-08:00
as appropriate.
Must be human readable. Not going to use Unix time.
How can I do this without spinning up a whole Extension?
Edit 1: Thank you much for incorporating this feature. Its so nice that every time a create a new timestamp, on Nov. 5th and beyond, it automatically shows -08:00
instead of -07:00
... ah, small win!
Upvotes: 1
Views: 978
Reputation: 182441
Indeed, coming to vscode v1.78 is a timezone offset variable, see new snippet variable for timezone_offset.
New snippet variable for timezone offset
A new snippet variable,
CURRENT_TIMEZONE_OFFSET
, is now available. This variable returns the current timezone offset in the format+HHMM
or-HHMM
(for example-0700
).
Upvotes: 0
Reputation: 721
I came here looking for the same thing. Its not a snippet, but I use the Insert Date String extension to handle this. You can define the default format as iso, and it comes with a key binding of ctrl-shift-alt-I. Works well enough, but I too would prefer a snippet.
Upvotes: 1