A plugin for Visual Studio Code that inserts the current date and/or time according to configured format. Available in VisualStudio Marketplace.
- Version 3.0 switched from
date-format-liteto dayjs for date formatting:- Token semantics for
h/hh/H/HHhave changed —HHis now 24-hour (was 12-hour) andhhis now 12-hour (was 24-hour). The default format has been updated. If you use a custom format withhhorHH, please review and update your settings. - Literal-text escape syntax changed:
date-format-liteused"text"or'text'(e.g.'T'); dayjs uses[text](e.g.[T]). If you use literal escaping in your format, update to the bracket syntax.
- Token semantics for
- Version 2.0 changed settings namespace from
insertdatestringtoinsertDateString. Please update your userspace and workspace settings.
Open Command Palette by pressing F1, type ext install and then look for Insert Date String extension.
Following commands are available:
Insert DateTime(⇧+⌘+I on OS X, Ctrl+Shift+I on Windows and Linux) - Inserts current date and/or time according to configured format (format) at the cursor position.Insert Date- Inserts current date according to configured format (formatDate) at the cursor position.Insert Time- Inserts current time according to configured format (formatTime) at the cursor position.Insert Timestamp- Inserts current timestamp in milliseconds at the cursor position.Insert Formatted DateTime(⇧+⌘+⌥+I on OS X, Ctrl+Alt+Shift+I on Windows and Linux) - Prompt user for format and insert formatted date and/or time at the cursor position. The last custom format entered is remembered per workspace using VS Code's workspace context which is separate from theinsertDateString.formatsetting and is not visible in your workspace settings file.Reset Workspace DateTime Format Override- Clears the workspace-stored format override, restoring theinsertDateString.formatsetting as the default forInsert Formatted DateTime.
- Date and time format string (this affects
Insert DateTimeoutput): - Date format string (this affects
Insert Dateoutput): - Time format string (this affects
Insert Timeoutput): - Timezone (applies to all format-based commands; leave empty for local system time):
// Date format to be used.
"insertDateString.format": "YYYY-MM-DD HH:mm:ss",
"insertDateString.formatDate": "YYYY-MM-DD",
"insertDateString.formatTime": "HH:mm:ss",
// Timezone (IANA name, e.g. "America/New_York"). Default: "" (local time).
"insertDateString.timezone": "",
Set insertDateString.timezone to an IANA timezone name to produce timestamps in a consistent timezone regardless of the local system clock. This is useful for distributed teams that need to agree on a shared reference timezone.
"insertDateString.timezone": "America/New_York"Supported values: Any IANA timezone name (e.g. UTC, America/New_York, Europe/Warsaw, Asia/Tokyo). Leave empty to use local system time.
Affected commands: Insert DateTime, Insert Date, Insert Time, Insert Formatted DateTime.
Unaffected commands: Insert Timestamp always produces a Unix timestamp in milliseconds (UTC by definition). The iso format token always outputs UTC regardless of this setting.
If the configured value is not a valid IANA timezone, a warning is shown and local system time is used as a fallback.
Format strings use dayjs token conventions.
- YY - Two-digit year. Examples: 99 or 03
- YYYY - Four-digit year. Examples: 1999 or 2003
- M - Month, without leading zeros. 1 through 12
- MM - Month, with leading zeros. 01 through 12
- MMM - Abbreviated month name. Jan through Dec
- MMMM - Full month name. January through December
- D - Day of the month, without leading zeros. 1 to 31
- DD - Day of the month, with leading zeros. 01 to 31
- d - Day of the week. 0 (Sunday) through 6 (Saturday)
- ddd - Abbreviated day name. Sun through Sat
- dddd - Full day name. Sunday through Saturday
- H - 24-hour format, without leading zeros. 0 through 23
- HH - 24-hour format, with leading zeros. 00 through 23
- h - 12-hour format, without leading zeros. 1 through 12
- hh - 12-hour format, with leading zeros. 01 through 12
- m - Minutes, without leading zeros. 0 through 59
- mm - Minutes, with leading zeros. 00 to 59
- s - Seconds, without leading zeros. 0 through 59
- ss - Seconds, with leading zeros. 00 to 59
- SSS - Milliseconds, with leading zeros. 000 to 999
- A - AM or PM
- a - am or pm
- Z - UTC offset. Examples: +05:30, -07:00
- ZZ - UTC offset without colon. Examples: +0530, -0700
- X - Unix timestamp in seconds
- x - Unix timestamp in milliseconds
- w - ISO weekday. 1 (Monday) through 7 (Sunday)
- W - ISO week number of year. First week is the week containing 4 January
- o - ISO week-year. Same as
YYYYexcept at year boundaries where the ISO week belongs to the adjacent year - iso - Special value: outputs a simplified ISO 8601 string in UTC (e.g.
2013-07-16T20:13:31Z)
- Year and month:
YYYY-MM(2013-07) - Complete date:
YYYY-MM-DD(2013-07-16) - Complete date and time:
YYYY-MM-DD HH:mm:ss(2013-07-16 20:13:31) - Complete date plus hours, minutes, seconds and UTC offset:
YYYY-MM-DDTHH:mm:ssZ(2013-07-16T20:13:31+01:00)
Released under the MIT License.