4.0.0 • Published 5 years ago

datetime-js v4.0.0

Weekly downloads
59
License
ISC
Repository
github
Last release
5 years ago

DateTime Script

Customize output for a javascript Date object

Installation

npm install datetime-js

Examples

var DateTime = require('datetime-js')
var dateObj = new Date()

DateTime(dateObj, 'The date is %m-%d-%Y');
//-> The date is 02-14-2014

DateTime(dateObj, 'Time Now: %h:%i %AMPM');
//-> Time Now: 04:45 PM

DateTime(dateObj, 'Today is the %d:o day of %M');
//-> Today is the 25th day of August

JSFiddle Examples


Format options

Month

FormatDescriptionValue Examples
%mMonth in number01 - 12
%MFull month nameJanuary - December
%M:sMonth in shorthandJan - Dec

Day

FormatDescriptionValue Examples
%dDay of the month01 - 31
%DDay of the weekMonday - Sunday
%D:sDay of the week shorthandMon - Sun
%d:oDay of the month with ordinal suffix1st 2nd 3rd 4th . . .

Year

FormatDescriptionValue Examples
%YYear in full format2019
%Y:rYear in Roman numeral formatMMXIX
%yYear in shorthand19

Time

FormatDescriptionValue Examples
%h12-hour format1 - 12
%H24-hour format00 - 23
%iMinutes0 - 59
%sSeconds0 - 59
%ampmam/pm lowercaseam pm
%AMPMam/pm uppercaseAM PM
%AmPmam/pm capitalizedAm Pm