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

date-format-lite

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-format-lite

Date format and parser for node.js and browser

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
@version    0.6.0
@date       2014-11-13
@stability  1 - Experimental

Date format – Build Coverage

Lite version of Date format and parse for node.js and browser that extends native Date object.

How to use

In browser

<script src=date-format.js></script>

In node.js

npm install date-format-lite

require("date-format-lite")

Usage

// Format
var now = new Date()          // Date {Wed Jul 10 2013 16:47:36 GMT+0300 (EEST)}
now.format("isoUtcDateTime")  // 2013-07-10T13:47:36Z
now.format("hh:mm")           // 16:47
now.format("UTC:hh:mm")       // 13:47

// Parse
"2013-07-10".date()           // Date {Wed Jul 10 2013 03:00:00 GMT+0300 (EEST)} 
"2013-07-10T13:47:36Z".date() // Date {Wed Jul 10 2013 16:47:36 GMT+0300 (EEST)}
"10/07/2013".date()           // Date {Wed Jul 10 2013 03:00:00 GMT+0300 (EEST)}
Date.middleEndian = true
"10/07/2013".date()           // Date {Mon Oct 07 2013 03:00:00 GMT+0300 (EEST)}
// Change format
"10/07/2013".date("YYYY-MM-DD")// 2013-07-10

Define default format

Date.masks.default = 'YYYY-MM-DD hh:mm:ss'
now.format()                  // 2013-07-10 13:47:36

Define custom formats

Date.masks.my = '"DayNo "D'
now.format("my")              // DayNo 10

Use another language

// Add to estonian-lang.js
Date.dayNames = "P E T K N R L pühapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev".split(" ")
Date.monthNames = "Jaan Veeb Märts Apr Mai Juuni Juuli Aug Sept Okt Nov Dets jaanuar veebruar märts aprill mai juuni juuli august september oktoober november detsember".split(" ")

// Change AM and PM
Date.am = "a.m."
Date.pm = "p.m."

See tests for more examples

Syntax

  • Y - A two digit representation of a year without leading zeros. Examples: 99 or 3
  • YY - A two digit representation of a year. Examples: 99 or 03
  • YYYY - A full numeric representation of a year, 4 digits. Examples: 1999 or 2003
  • M - Numeric representation of a month, without leading zeros. 1 through 12
  • MM - Numeric representation of a month, with leading zeros. 01 through 12
  • MMM - A short textual representation of a month, three letters. Jan through Dec
  • MMMM - A full textual representation of a month, such as January or March. January through December
  • D - Day of the month without leading zeros. 1 to 31
  • DD - Day of the month, 2 digits with leading zeros. 01 to 31
  • DDD - A textual representation of a day, three letters. Mon through Sun
  • DDDD - A full textual representation of the day of the week. Sunday through Saturday
  • H - 12-hour format of an hour without leading zeros. 1 through 12
  • HH - 12-hour format of an hour with leading zeros. 01 through 12
  • h - 24-hour format of an hour without leading zeros. 0 through 23
  • hh - 24-hour format of an hour with leading zeros. 00 through 23
  • m - Minutes without leading zeros. 0 through 59
  • mm - Minutes with leading zeros. 00 to 59
  • s - Seconds without leading zeros. 0 through 59
  • ss - Seconds with leading zeros. 00 to 59
  • S - Milliseconds without leading zeros. 0 through 999
  • SS - Milliseconds with leading zeros. 000 to 999
  • u - Milliseconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  • U - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  • A - Ante meridiem and Post meridiem. AM or PM
  • Z - Difference to Greenwich time (GMT) with colon between hours and minutes. Example: GMT +02:00
  • "text" - text, quotes should be escaped, eg '"a \"quoted text\"" YYYY'
ISO-8601
  • w - Day of the week. 1 (for Monday) through 7 (for Sunday)
  • W - Week number of year, first week is the week with 4 January in it
  • o - ISO-8601 year number. This has the same value as YYYY, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead

Notes

  • If no UTC relation information is given with a time representation, the time is assumed to be in local time.
  • If the time is in UTC, add a Z directly after the time without a space.

ToDo

  • Add timezone support for Date.format

Browser Support

It should work IE6 and up but automated testing is currently broken.

Licence

Copyright (c) 2012-2014 Lauri Rooden <lauri@rooden.ee>
The MIT License

Keywords

FAQs

Package last updated on 13 Nov 2014

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