date_time_formatter
v1.0.24
Published
This package contains a function for formatting date objects into customizable formats
Maintainers
Readme
date_time_formatter
Installation
$ npm install date_time_formatterUsage
var dateTimeFormatter = require('date_time_formatter');
var now = new Date();
dateTimeFormatter.formatDate(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM
dateTimeFormatter.formatDate(now, "W");
// 42
dateTimeFormatter.formatDate(now,"N");
// 6Format options
Option | Description
---- | ----
d | Date
dd | Date with leading zero
ddd | First three letters of day of week
dddd | Full name for day of week
m | Month
mm | Month with leading zero
mmm | First three letters of the month.
mmmm | Month's full name.
yy | Year as last two digits
yyyy | Full Year.
h | Hours (12-hour clock).
hh | Hours with leading zero (12-hour clock).
H | Hours (24 hour)
HH | Hours with leading zero (24 hour)
M | Minutes
MM | Minutes with leading zero
N | Day of Week. Ex. Monday is 1
o | Time zone offset string
s | Seconds
ss | Seconds with leading zero
S | st, nd, rd, or th
l | 3 digit Milliseconds
L | 2 digit Milliseconds
t | a or p.
tt | am or pm.
T | A or P.
TT | AM or PM.
W | Current week in the year
... | Surround text with this to print directly in the string
Localization of text
You can use the following to change names for days and months for your area.
dateTimeFormatter.i18n.texts = {
longDayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
shortDayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
longMonthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
shortMonthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}