torufuruya / DateFormat.js

Extension of the Javascript Date Object to format date

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DateFormat.js Build Status

Extension of the Javascript Date object with a minimum function for shaping the date.

Installation

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"

Usage

Supported format type

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

Example

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

test with karma, mocha, and chai

$ npm install -g karma
$ npm install
$ karma start

License

The MIT License (MIT)

Copyright (c) 2014 torufuruya

About

Extension of the Javascript Date Object to format date


Languages

Language:JavaScript 100.0%