Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

tinytime

> 编程语言
Open source

⏰ A straightforward date and time formatter in <1kb

1.3K stars0 likes3 views
WebsiteGitHub

About

⏰ A straightforward date and time formatter in <1kb

Tinytime ⏰

A straightforward date and time formatter in 1

  • YYYY - Full Year (1992)
  • YY - Partial Year (92)
  • dddd - Day of the Week (Monday)
  • DD - Day of the Month (24)
  • Do - Day (24th)
  • h - Hours - 12h format
  • H - Hours - 24h format
  • mm - Minutes (zero padded)
  • ss - Seconds (zero padded)
  • a - AM/PM

1 - you get padded months (09 instead of 9) by passing in the padMonth option.

javascript
const template = tinytime('{Mo}', { padMonth: true })

Efficiency

tinytime takes an approach similar to a compiler and generates an AST representing your template. This AST is generated when you call the main tinytime function. This lets you efficiently re-render your template without tinytime having to parse the template string again. That means its important that you aren't recreating the template object frequently.

Here's an example showing the right and wrong way to use tinytime with React.

Don't do this:

javascript
function Time({ date }) {
  return (
    

  )
}

Instead, only create the template object once, and just re-render it.

javascript
const template = tinytime('{h}:{mm}:{ss}{a}');
function Time({ date }) {
  return (
    

  )
}

Babel Plugins

Using one of the plugins below, you can resolve this efficiency concern at compile time.

babel-plugin-transform-tinytime - Hoists tinytime calls out of the JSX render scope.

babel-plugin-tinytime - Hoists tinytime calls out of the current scope, regardless if its inside JSX or a ordinary function scope.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptdatetemplatetime

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言