Browse the docs

kmDateTime

Formats now, or a moment offset from now, with a date format pattern.

Keyboard Maestro: ICUDateTimePlus, ICUDateTimeMinus, ICUDateTimeFor

Details #

kmDateTime(format, mode, amount) takes exactly three arguments and returns text.

format is a date pattern in Unicode (ICU) style, such as yyyy-MM-dd HH:mm. It is used in the Mac's time zone.

mode is "plus", "minus" or "for".

  • plus and minus start from now. amount is a number of seconds, or words like 2 days, 1 hour 30 minutes, 3 weeks. Seconds, minutes, hours, days, weeks, months and years are understood, singular or plural, and several can be combined.

  • for formats a fixed moment; amount is a time in seconds since 1 January 1970 (what time returns).

  • Any other mode is treated as plus.

Parameters #

Takes 3 arguments. {{ kmDateTime(text, b, c) }}

Examples #

kmDateTime("yyyy", "for", 1700000000)
→ 2023
kmDateTime("EEEE d MMMM", "plus", "2 days")
→ Saturday 17 January
kmDateTime("HH:mm", "minus", 3600)
→ 08:30

Gotchas #

  • Amount text without a recognisable number and unit stops the step: an amount of time looks like 90, 2 days or 1 hour 30 minutes, got "...".

  • Months and years move by calendar, so 1 month from 31 January lands on the Mac calendar's idea of the next month, not 30 days.

  • Pattern letters are case-sensitive: MM is month, mm minutes, yyyy the year, HH the 24-hour clock.