Date Time Shortcut

When writing Markdown in VS Code it’s useful to be able to insert the current date and time quickly. You can do this by setting up a keyboard shortcut1 that inserts the current date and time in a specific format.

To set up a date time shortcut in VS Code, follow these steps:

  1. Open the command palette by pressing Ctrl+Shift+P (or Cmd+Shift+P on macOS).

  2. Type “Preferences: Open Keyboard Shortcuts (JSON)” and select it.

  3. Add the following JSON snippet to your keybindings.json file

    },
    {
        "key": "ctrl+d t",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
            "snippet": "$CURRENT_YEAR-$CURRENT_MONTH-${CURRENT_DATE}T$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND.000"
        }
    }
    
  4. Save the file.

  5. Now, whenever you press Ctrl+d t (or your chosen key combination), it will insert the current date and time in the format YYYY-MM-DDTHH:MM:SS.000.