简体   繁体   中英

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM