Search code examples
visual-studio-codetimestampcode-snippetsvscode-snippets

How to insert characters inline VS Code Snippet?


Trying to create a timestamp snippet in VS Code that produces yyyy-MM-ddThh:mm:ssZ.

Tried so far:

$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE","T","$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND","Z" but the commas place each section on a new line.

2021-06-27
T
08:57:03
Z

How do I get the "T" and "Z" characters inline here?


Solution

  • You have to do two things:

    1. Put the whole thing on one line - the ,'s are seen as line breaks.
    2. Wrap each variable in ${....} so that they work properly with the other charcters T and Z right next to them. Otherwise the variables cannot be interpreted properly. So:

    "${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}Z"