Skip to content

jsynowiec/vscode-insertdatestring

Repository files navigation

VSCode extension - Insert Date String

Sponsor Version Ratings Installs License

A plugin for Visual Studio Code that inserts the current date and/or time according to configured format. Available in VisualStudio Marketplace.

Breaking Changes

  • Version 3.0 switched from date-format-lite to dayjs for date formatting:
    • Token semantics for h/hh/H/HH have changed — HH is now 24-hour (was 12-hour) and hh is now 12-hour (was 24-hour). The default format has been updated. If you use a custom format with hh or HH, please review and update your settings.
    • Literal-text escape syntax changed: date-format-lite used "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.
  • Version 2.0 changed settings namespace from insertdatestring to insertDateString. Please update your userspace and workspace settings.

Installation

Open Command Palette by pressing F1, type ext install and then look for Insert Date String extension.

Usage

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 the insertDateString.format setting and is not visible in your workspace settings file.
  • Reset Workspace DateTime Format Override - Clears the workspace-stored format override, restoring the insertDateString.format setting as the default for Insert Formatted DateTime.

Available settings

  • Date and time format string (this affects Insert DateTime output):
  • Date format string (this affects Insert Date output):
  • Time format string (this affects Insert Time output):
  • 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": "",

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.

Syntax

Format strings use dayjs token conventions.

Year

  • YY - Two-digit year. Examples: 99 or 03
  • YYYY - Four-digit year. Examples: 1999 or 2003

Month

  • 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

Day

  • 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

Hour

  • 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

Minute, second, millisecond

  • 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

AM/PM and timezone

  • A - AM or PM
  • a - am or pm
  • Z - UTC offset. Examples: +05:30, -07:00
  • ZZ - UTC offset without colon. Examples: +0530, -0700

Unix timestamps

  • X - Unix timestamp in seconds
  • x - Unix timestamp in milliseconds

ISO week tokens

  • 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 YYYY except 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)

Examples

  • 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)

License

Released under the MIT License.

About

An extension for Visual Studio Code that provides a configurable command for inserting the current date and time

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors