Extension of the Javascript Date object with a minimum function for shaping the date.
download
$ git clone https://github.com/torufuruya/DateFormat.js.git
OR you can also download by using bower
$ bower install dateformatjs
and read in your HTML
<script type="text/javascript" src="dateformat.js"></script>
then you can use Date.prototype.format function
var d = new Date();
d.format('Y-m-d H:i:s'); //=> e.g. "2014-01-14 00:00:00"
- Y: A full numeric representation of a year, 4 digits.
- m: Numeric representation of a month, with leading zeros.
- n: Numeric representation of a month, without leading zeros.
- d: Day of the month, 2 digits with leading zeros.
- j: Day of the month without leading zeros.
- H: 24-hour format of an hour with leading zeros.
- h: 12-hour format of an hour with leading zeros.
- i: Minutes with leading zeros.
- s: Seconds, with leading zeros.
var d = new Date(1388599445000);
d.format('Y-m-d H:i:s') //=> "2014-01-02 03:04:05"
d.format('n/j h:i') //=> "1/2 3:04"
test with karma, mocha, and chai
$ npm install -g karma
$ npm install
$ karma start
The MIT License (MIT)
Copyright (c) 2014 torufuruya