litejs

@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

ISO-8601

Notes

ToDo

Browser Support

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

Licence

Copyright (c) 2012-2014 Lauri Rooden <[email protected]>
The MIT License

Fork me on GitHub

Since 2013 to 2015