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:
- Open the command palette by pressing
Ctrl+Shift+P
(orCmd+Shift+P
on macOS). - Type “Preferences: Open Keyboard Shortcuts (JSON)” and select it.
- Add the following JSON snippet to your
keybindings.json
file1}, 2{ 3 "key": "ctrl+d t", 4 "command": "editor.action.insertSnippet", 5 "when": "editorTextFocus", 6 "args": { 7 "snippet": "$CURRENT_YEAR-$CURRENT_MONTH-${CURRENT_DATE}T$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND.000" 8 } 9}
- Save the file.
- Now, whenever you press
Ctrl+d t
(or your chosen key combination), it will insert the current date and time in the formatYYYY-MM-DDTHH:MM:SS.000
.