明天在VS代码段中插入日期

发布于 2025-01-23 20:32:19 字数 825 浏览 4 评论 0原文

我有一个 alfred noreferrer“> alfred sminippet your to in of Me of Me of Me of Mearly of Alfred noreferrer”> alfred noreferrer 这就是它的外观:

## Week (4/25–4/29)
- [ ] 

### Monday Apr 25, 2022
- [ ] Snippet

----

我想将其移至a vs code snippet < /a>。 VS代码定义了环境变量,例如$ current_year$ current_month_name_short可以填写其中的一些。但是在“周(4/25-4/29)”线上,我真的很想在下一个星期五(通常是从今天起四天)的日期。有什么方法可以使用VS代码段?

作为参考,这就是我的阿尔弗雷德的定义:

## Week ({date:M/d}–{date +4d:M/d})
- [ ] 

### Monday {date}
- [ ] Snippet

----

I have an Alfred Snippet that types the outline of a weekly Markdown checklist for me. Here's what it comes out looking like:

## Week (4/25–4/29)
- [ ] 

### Monday Apr 25, 2022
- [ ] Snippet

----

I'd like to move this over to a VS Code Snippet. VS Code defines environment variables like $CURRENT_YEAR and $CURRENT_MONTH_NAME_SHORT that can fill out some of this. But for the "Week (4/25-4/29)" line, I'd really like to have the date for the next Friday (usually four days from today). Is there any way to do this with a VS Code snippet?

For reference, this is how my Alfred is defined:

## Week ({date:M/d}–{date +4d:M/d})
- [ ] 

### Monday {date}
- [ ] Snippet

----

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散 2025-01-30 20:32:19

使用VSC片段,这是不可能的。

使用扩展 file noreferrer“> file模板(v1.10.0)生成日期/时间是现在的特定偏移。

您必须定义您的首选dateTimeFormat设置。

定义以下设置(我们具有命名的日期格式:week-schedule

是全局或工作空间中

  "templates.dateTimeFormat": {
    "locale": "en-US",
    "options": {
      "year": "numeric",
      "month": "2-digit",
      "day": "2-digit",
      "weekday": "long",
      "hour12": false,
      "hour": "2-digit",
      "minute": "2-digit",
      "second": "2-digit"
    },
    "template": "${month}/${day}"
    "week-schedule": {
      "options": {
        "year": "numeric",
        "month": "short",
        "day": "2-digit",
        "weekday": "long",
      },
      "template": "${weekday} ${month} ${day}, ${year}"
    }
  }

定义以下模板(全局或工作空间中)

可以 .md

##@@## ${dateTimeFormat#template=${year}-${month}-${day}#offset=+1WD0 +1D#}_${dateTimeFormat#template=${month}-${day}#offset=+1WD0 +5D#}${input#Additional#find=^(.+)$#replace=-$1#}
## Week (${dateTimeFormat:offset=+1WD0 +1D:}–${dateTimeFormat:offset=+1WD0 +5D:})
- [ ] 

### ${dateTimeFormat:week-schedule:offset=+1WD0 +1D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +2D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +3D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +4D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +5D:}
- [ ] Snippet

----

它将使用日期和一些(可选)附加文本创建一个文件名。

第一行需要这么长。整个文件名模板必须在第1行中。

模板可以包含VSC摘要和输入字段以及其他一些变量。


编辑

在V1.11.0中有一个命令templates.pasteTemplate您可以在其中插入使用键绑定的模板

  {
    "key": "ctrl+alt+w",  // or any other combo
    "command": "templates.pasteTemplate",
    "args": {
      "text": [
        "## Week (${dateTimeFormat:week-schedule-head:offset=+1wd0 +1d:}–${dateTimeFormat:week-schedule-head:offset=+1wd0 +5d:})",
        "- [ ]",
        "",
        "### ${dateTimeFormat:week-schedule:offset=+1wd0 +1d:}",
        "- [ ] Snippet",
        "",
        "----"
      ]
    }
  }

With the VSC snippets it is not possible.

With the extension File Templates (v1.10.0) you can generate dates/times that are a particular offset from now.

You have to define your preferred dateTimeFormat setting.

Define the following setting (we have a named date format: week-schedule)

Can be Global or in your Workspace

  "templates.dateTimeFormat": {
    "locale": "en-US",
    "options": {
      "year": "numeric",
      "month": "2-digit",
      "day": "2-digit",
      "weekday": "long",
      "hour12": false,
      "hour": "2-digit",
      "minute": "2-digit",
      "second": "2-digit"
    },
    "template": "${month}/${day}"
    "week-schedule": {
      "options": {
        "year": "numeric",
        "month": "short",
        "day": "2-digit",
        "weekday": "long",
      },
      "template": "${weekday} ${month} ${day}, ${year}"
    }
  }

Define the following template (Global or in your Workspace)

week-schedule.md

##@@## ${dateTimeFormat#template=${year}-${month}-${day}#offset=+1WD0 +1D#}_${dateTimeFormat#template=${month}-${day}#offset=+1WD0 +5D#}${input#Additional#find=^(.+)$#replace=-$1#}
## Week (${dateTimeFormat:offset=+1WD0 +1D:}–${dateTimeFormat:offset=+1WD0 +5D:})
- [ ] 

### ${dateTimeFormat:week-schedule:offset=+1WD0 +1D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +2D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +3D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +4D:}
- [ ] Snippet

----

### ${dateTimeFormat:week-schedule:offset=+1WD0 +5D:}
- [ ] Snippet

----

It will create a filename with the dates and some (optional) additional text.

The first line needs to be that long. The whole filename template must be on line 1.

The template can contain VSC snippets and input fields and a few other variables.


Edit

In v1.11.0 there is a command templates.pasteTemplate where you can insert a Template with a key binding

  {
    "key": "ctrl+alt+w",  // or any other combo
    "command": "templates.pasteTemplate",
    "args": {
      "text": [
        "## Week (${dateTimeFormat:week-schedule-head:offset=+1wd0 +1d:}–${dateTimeFormat:week-schedule-head:offset=+1wd0 +5d:})",
        "- [ ]",
        "",
        "### ${dateTimeFormat:week-schedule:offset=+1wd0 +1d:}",
        "- [ ] Snippet",
        "",
        "----"
      ]
    }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文