All Projects → lukeed → Tinydate

lukeed / Tinydate

Licence: mit
A tiny (349B) reusable date formatter. Extremely fast!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tinydate

Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (-89.49%)
Mutual labels:  time, date, datetime, timestamp, format
Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (-85.05%)
Mutual labels:  time, date, datetime, format
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-96.67%)
Mutual labels:  time, datetime, date, format
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-97.58%)
Mutual labels:  time, datetime, date, format
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (-97.47%)
Mutual labels:  datetime, date, format, timestamp
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-97.07%)
Mutual labels:  time, datetime, date
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+368.59%)
Mutual labels:  time, date, datetime
Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (-42.93%)
Mutual labels:  time, date, datetime
Period
PHP's time range API
Stars: ✭ 616 (-37.78%)
Mutual labels:  time, date, datetime
dt
Go's missing DateTime package
Stars: ✭ 34 (-96.57%)
Mutual labels:  time, datetime, date
ember-dayjs-helpers
Ember Template helpers based on day.js
Stars: ✭ 19 (-98.08%)
Mutual labels:  datetime, date, format
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-96.36%)
Mutual labels:  time, datetime, date
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (-89.8%)
Mutual labels:  time, datetime, date
chronos
One library to rule the time
Stars: ✭ 17 (-98.28%)
Mutual labels:  time, datetime, date
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (-45.86%)
Mutual labels:  time, date, datetime
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (-94.04%)
Mutual labels:  time, datetime, date
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-95.86%)
Mutual labels:  time, datetime, date
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-70.3%)
Mutual labels:  time, date, datetime
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-98.28%)
Mutual labels:  time, date, format
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (-6.26%)
Mutual labels:  time, date, datetime

tinydate CI

A tiny (349B) reusable date formatter. Extremely fast!

Demo

Inspired by tinytime, this module returns a "render" function that efficiently re-render your deconstructed template. This allows for incredibly performant results!

However, please notice that this only provides a limited subset of Date methods.
If you need more, tinytime or date-fns are great alternatives!

Install

$ npm install --save tinydate

Usage

const tinydate = require('tinydate');
const fooDate = new Date('5/1/2017, 4:30:09 PM');

const stamp = tinydate('Current time: [{HH}:{mm}:{ss}]');

stamp(fooDate);
//=> Current time: [16:30:09]

stamp();
//=> Current time: [17:09:34]

API

tinydate(pattern, dict?)(date?)

Returns: Function

Returns a rendering function that will optionally accept a date value as its only argument.

pattern

Type: String
Required: true

The template pattern to be parsed.

dict

Type: Object
Required: false

A custom dictionary of template patterns. You may override existing patterns or declare new ones.

Important: All dictionary items must be a function and must control its own formatting.
For example, when defining your own {ss} template, tinydate will not pad its value to two digits.

const today = new Date('2019-07-04, 5:30:00 PM');

// Example custom dictionary:
//   - Adds {MMMM}
//   - Overrides {DD}
const stamp = tinydate('Today is: {MMMM} {DD}, {YYYY}', {
	MMMM: d => d.toLocaleString('default', { month: 'long' }),
	DD: d => d.getDate()
});

stamp(today);
//=> 'Today is: July 4, 2019'

date

Type: Date
Default: new Date()

The date from which to retrieve values. Defaults to current datetime if no value is provided.

Patterns

  • {YYYY}: full year; eg: 2017
  • {YY}: short year; eg: 17
  • {MM}: month; eg: 04
  • {DD}: day; eg: 01
  • {HH}: hours; eg: 06 (24h)
  • {mm}: minutes; eg: 59
  • {ss}: seconds; eg: 09
  • {fff}: milliseconds; eg: 555

Benchmarks

# Node v10.13.0

tinydate    x 160,834,214 ops/sec ±0.21% (96 runs sampled)
tinytime    x  44,602,162 ops/sec ±0.34% (97 runs sampled)
time-stamp  x     888,153 ops/sec ±1.27% (86 runs sampled)

License

MIT © Luke Edwards

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].