0

So I've now got this great timestamp inside a code snippet in VS Code.

Full snippet:

"Frontmatter":{
        "prefix": "sqFront",
        "body": [
            "---",
            "title: $1",
            "permalink: $2",
            "description: $3",
            "date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}Z",
            "tags:",
              "- $0",
            "---"
        ]
    }

How do I set the snippet to capture UTC time instead of my local time?

1
  • Some options here: maybe one of the extensions mentioned there. Commented Jun 27, 2021 at 17:04

1 Answer 1

1

You can use the HyperSnips extension:

Define the following snippet in the language.hsnips file or in all.hsnips file if you want to have it many file types

snippet sqFront "Frontmatter" b
---
title: $1
permalink: $2
description: $3
date: `` d = new Date();
twodigit = n => n.toString().padStart(2,'0');
rv = `${d.getUTCFullYear()}-${twodigit(d.getUTCMonth()+1)}-${twodigit(d.getUTCDate())}T${twodigit(d.getUTCHours())}:${twodigit(d.getUTCMinutes())}:${twodigit(d.getUTCSeconds())}Z` ``
tags:
- $0
---
endsnippet
Sign up to request clarification or add additional context in comments.

3 Comments

Do you know of a way to do this natively? I've got all my extensions dialed at the moment. Sometime introducing another one causes breakage. Would prefer to do this natively if its possible.
@SeaDude most (native) VSC behavior is done with extensions, so if you eliminate extensions VSC does nothing
Gotcha. I was thinking since there are built-in variables such as CURRENT_HOUR, etc. there may be a built in CURRENT_HOUR_UTC or the like. Or a way to define a timezone that VS Code uses for a snippet, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.