1.6.4 • Published 5 years ago

s-date v1.6.4

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

s-date

NPM version Dependencies build status NPM license

Same general purpose as moment.js, but in ~1kb minified.

This CommonJS module exports a single function that takes two parameters. The first is a format string, the second is an optional Date. If the date is omitted, it defaults to new Date();.

If you don't need full customizability for your date string, you probably don't need this library. Just use Date.toLocaleDateString() and related methods.

Usage

var date = require('s-date');

var myBirthday = new Date(1994, 10, 7);
date('{mm}/{dd}/{yyyy}', myBirthday); // '11/07/1994'

Formatting options

Example: For January 2, 2053 4:30pm + 45 seconds

String templateOutput exampleMeaning
{yyyy}20534-digit year
{yy}532-digit year
{mm}012-digit month
{m}1unpadded month
{Month}Januarymonth name
{Mo}Janmonth shortname
{d}2date
{ds}2nddate + suffix
{dd}022-digit date
{Weekday}Thursdayday of the week
{Day}Thuday shortname
{Dy}Thday shortername
{D}T1-char day name
{h24}16unpadded hours (24)
{hh24}16hours (24)
{hh}04hours (12)
{h}4unpadded hours (12)
{ampm}pmam/pm
{AMPM}PMAM/PM
{Minutes}30Minutes (padded)
{Seconds}45Seconds (padded)

To output the example above...

// Date(year, month-1, date, hours, minutes, seconds)
var someDay = new Date(2053, 0, 2, 4, 30, 45);
date('{Month} {d}, {yyyy} {h}:{Minutes}{ampm} + {Seconds} seconds', someDay);

Benchmarks

Run using benchmark.js on 2.3GHz Macbook Pro

s-date    x 428,936 ops/sec ±2.29% (79 runs sampled)
moment    x 271,963 ops/sec ±1.34% (85 runs sampled)
date-fns  x 196,827 ops/sec ±1.17% (80 runs sampled)
dayjs     x 121,425 ops/sec ±1.99% (87 runs sampled)
luxon     x 90,782 ops/sec ±1.13% (83 runs sampled)
Fastest is s-date
1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago