0

How can I insert date and time in 12 hour format using keybindings.json without installing additional extensions or apps? It's running on a low end PC, and additional apps or installations aren't desirable.

I'm new to Visual Studio Code. I'm using my keybindings.json from another post:

    {
        "key": "cmd+k t",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
            "snippet": "$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE
                        $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND"
        }
    }
]

This snippet is giving me time in 24-hour format. I couldn't find any 12-hour hour variable.

Another post URL: How to insert current date time in vscode?

Robert
  • 1
  • 3
  • why no other extension? The whole of VSC is implemented in extensions – rioV8 Mar 25 '22 at 19:27
  • 1
    There is no way to get a 12 hour format without an extension as you see the built-in variable returns 24-hour format and there is no setting or option to change that. – Mark Mar 25 '22 at 19:55
  • It's running on a low end PC, and additional apps or installations aren't desirable. – Robert Mar 25 '22 at 21:59
  • any idea how big VSC is and the language extensions, an extension of 10K won't hurt you, every new release of VSC gets bigger and bigger, and you update VSC, what about all the new build-in extensions you can't remove – rioV8 Mar 27 '22 at 14:21

1 Answers1

1

Check out this solution here (not mine) using some regular expressions:

{
    "Now": {
        "prefix": "now",
        "description": "Insert a short time and date",
        "scope": "markdown",
        "body": [
            "${CURRENT_HOUR/(13)|(14)|(15)|(16)|(17)|(18)|(19)|(20)|(21)|(22)|(23)|0(.)/${1:+1}${2:+2}${3:+3}${4:+4}${5:+5}${6:+6}${7:+7}${8:+8}${9:+9}${10:+10}${11:+11}$12/}:$CURRENT_MINUTE${CURRENT_HOUR/(0.|10|11)/${1:?am:pm}/} ${CURRENT_DATE/0(.)/$1/} $CURRENT_MONTH_NAME_SHORT $CURRENT_YEAR_SHORT",
        ]
    }
}

From: https://mybyways.com/blog/vs-code-snippet-to-insert-formatted-date-and-time

joeshmo
  • 158
  • 1
  • 13