Home

Awesome

Date Stylish NPM version GitHub version

NPM

Date and time with style.

Install

$ npm install --save-dev

Usage

var ds = require('date-stylish');

Example

var ds = require('date-stylish'),
    nw = ds.now,
    in = ds.inow,
    Y  = ds.YYYY,
    M  = ds.MM,
    D  = ds.DD,
    h  = ds.hh,
    m  = ds.mm;

// Get the current time
console.log('Current date: %s', nw);            // => Current time: 19/06/2014 - 15:50:25

// Get the current time (with inverse date)
console.log('Current date: %s', in);            // => Current time: 2014/06/19 - 15:50:25

// Get custom date/time
console.log('%s/%s/%s - %s:%s', Y,M,D,h,m);     // => 2014/06/19 - 15:50
console.log('%s/%s/%s - %s:%s', D,M,Y,h,m);     // => 19/06/2014 - 15:50
console.log('%s/%s/%s', Y,M,D);                 // => 2014/06/19
console.log('%s/%s/%s', D,M,Y);                 // => 19/06/2014

// Set published date (great for blog posts)
var pubDate = ds.now;
console.log('Published at: %s' + pubDate);      // => Published at: 19/06/2014 - 15:50:25

// Pretty up dates other than the current one:
var oldDate = new Date(0);
ds.set( oldDate );
console.log('Remember back when we started the clock?  I believe it was ' + ds.YYYY);

Options

OptionsTypeReturnOutput
nowdateStringDD/MM/YYYY - hh:mm:ss
inowdateStringYYYY/MM/DD - hh:mm:ss
YYYYdateStringfull year
MMdateStringmonth
DDdateStringdate
hhdateStringhours
mmdateStringminutes
ssdateStringseconds
setfunc_null _sets internal time

Contribute

Feel free to contribute with this project or leave a suggestion.

License

MIT License © Vitor Britto