Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

s-date

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

s-date

Tiny date/time formatter

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

s-date

NPM version Dependencies build status NPM license Test Coverage

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

License

Copyright (c) 2015, Sebastian Sandqvist s.github@sparque.me

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Keywords

FAQs

Package last updated on 25 Oct 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc