1.1.5 • Published 7 years ago

date-format-simple v1.1.5

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

date-format-simple

simple JavaScript date library for formatting dates.

output

  • a few seconds ago
  • 30 seconds ago
  • a minute ago
  • 3 minutes ago
  • an hour ago
  • 5 hours ago
  • a days ago
  • 30 days ago
  • a month ago
  • 11 months ago
  • a year ago
  • 2 years ago

Install

$npm install date-format-simple

Usage

var DateFormat = require( 'date-format-simple' );

var today = new Date();
var myDate = new Date( 2015, 5, 10 );

var dateFormat = new DateFormat( today.getTime() );
dateFormat.print( myDate.getTime() );

dateFormat.toGMTDate( '2016-02-02T07:09:32.277Z' );

API

new DateFormat( milisecond, [options] );
var dateFormat = new DateFormat( milisecond );
dateFormat.print( milisecond );

options

var dateFormat = new DateFormat( 2016, 3, 10, {
  'a_few_seconds_ago': 'just now',
  'months_ago': 'months ago~ :D'
}, false, 'YYYY-MM-DD' );

// new DateFormat( date, msg, isGMT = false, dateFormat = 'YYYY-MM-DD' )

dateFormat.print( new Date( 2016, 1, 10 ) );
//result => 2 months ago~ :D

dateFormat.print( new Date( 2016, 3, 9, 23, 59, 59 ) );
//result => just now

default options

{
  'a_few_seconds_ago': 'a few seconds ago',
  'seconds_ago': 'seconds ago',

  'a_minute_ago': 'a minute ago',
  'minutes_ago': 'minutes ago',

  'an_hour_ago': 'an hour ago',
  'hours_ago': 'hours ago',

  'a_day_ago': 'a day ago',
  'days_ago': 'days ago',

  'a_month_ago': 'a month ago',
  'months_ago': 'months ago',

  'a_year_ago': 'a year ago',
  'years_ago': 'years ago'
}

build

  • npm install babel -g
  • npm run compile

Test

  • npm install mocha -g
  • npm test

License

© 2016 ingpdw. MIT License

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.28

10 years ago

1.0.27

10 years ago

1.0.26

10 years ago

1.0.25

10 years ago

1.0.24

10 years ago

1.0.23

10 years ago

1.0.21

10 years ago

1.0.20

10 years ago

1.0.18

10 years ago

1.0.17

10 years ago

1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.1.0

10 years ago