Use VSCode snippet to add timestamp

2025-02-20 · 1 min read

I know, all are well written in the documentation. This is a note for myself to use VSCode/VSCodium snippets in Linux.

  • Setup a snippet by clicking Ctrl + Shift + P, select Snippets: Configure Snippets.

  • Select New Global Snippets file...

  • Put something like this inside the snippet:

{
	"Insert timestamp": {
		"prefix": "date",
		"description": "Output a date in timestamp (YY-MM-DDHH:MM:SS)",
		"body": [
			"$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
		]
	}
}

This snippet can add a timestamp to any files you want. The prefix of the snippet is date. Remember this.

  • Open any files and type date. I hope I can see autocomplete pops up but nothing.

  • Go to menu, click Preferences -> Settings.

  • Setup "Editor: Tab Completion" to onlySnippets, if it was off originally

Go to your file, type date and click Tab key. Ta-da, see a timestamp in your file!

You can also add multiple lines like this in the body.

"body": [
	"## $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
	"### A title",
	"- ",
	"",
	"### Something here",
	"- ",
	"",
	"### Another thing here",
	"- ",
	"",
]

Done!



Written by Yuki Cheung

Hey there, I am Yuki! I'm a front-end software engineer who's passionate about both coding and gaming.

When I'm not crafting code, you'll often find me immersed in the worlds of Fire Emblem and The Legend of Zelda—those series are my absolute favorites! Lately, I've been delving into the fascinating realm of AI-related topics too.