Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard short cut to insert current date and/or time? #1147

Open
rhaynes74 opened this issue Nov 11, 2024 · 2 comments
Open

keyboard short cut to insert current date and/or time? #1147

rhaynes74 opened this issue Nov 11, 2024 · 2 comments

Comments

@rhaynes74
Copy link

Hi folks, is there a builtin shortcut to insert current date and / or time?

@v-shenoy
Copy link
Contributor

v-shenoy commented Nov 11, 2024

It would be convenient to have features similar to the natural-language-dates plugin for Obsidian, although not all that necessary.

The other alternative is to achieve this global using a text-expander such as espanso

@LumenYoung
Copy link

LumenYoung commented Nov 11, 2024

No builtin yet, but you can easily achieve that with the following template and space script

template:

---
tags: template
description: "Current time"
hooks.snippet.slashCommand: cc
---
{{currenttime}} 1|^|

space script:

/* get current local date and time */
silverbullet.registerFunction({name: "localtime"}, () => {
  const options = {
    timezone: 'Europe/Berlin',
    hour12: false,
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  };

  const d = new Date();
  let t = d.toLocaleString('en-US',options); /* mm/dd/yyyy, HH:MM:ss */
  t = t.replace(/,/,'');
  t = t.slice(6,10) + '-' + /* yyyy */
      t.slice(0,2) + '-' +  /* mm */
      t.slice(3,5) + ' ' +  /* dd */
      t.slice(-8);          /* HH:MM:ss */

  return t; /* yyyy-mm-dd HH:MM:ss */
})

/* get current time without date */
silverbullet.registerFunction({name: "currenttime"}, () => {
  const options = {
    timezone: 'Europe/Berlin',
    hour12: false,
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  };

  const d = new Date();
  let t = d.toLocaleString('en-US',options); /* mm/dd/yyyy, HH:MM:ss */

  return t; /* dd HH:MM:ss */
})

/* get current year */
silverbullet.registerFunction({name: "currentyear"}, () => {
  const d = new Date();
  let year = d.getFullYear(); // Gets the full year

  return year.toString(); /* yyyy */
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants