Socket
Socket
Sign inDemoInstall

s-date

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    s-date

Tiny date/time formatter


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Install size
84.5 kB
Created
Weekly downloads
 

Readme

Source

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();.

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);

Keywords

FAQs

Last updated on 08 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc