1.0.1 • Published 4 years ago

@evokegroup/dateformat v1.0.1

Weekly downloads
10
License
ISC
Repository
bitbucket
Last release
4 years ago

@evokegroup/dateformat

Adds date string formating to the Date prototype

Date.MonthNames

Array of month names in english

Date.MonthIndexes

Maps month names to the numeric month

Date.DayNames

Array of day names in english

Date.DayIndexes

Maps day names to the numeric day

Date.prototype.toStringFormat(formatString, makeUTC)

Outputs a Date into a string of given format

Parameters

ParameterTypeDefaultDescription
formatStringstringThe string format. See Format String section for details.
makeUTCbooleanfalseOutput the date string as UTC

Format String

StringDescription
dThe day of the month, from 1 through 31
ddThe day of the month, from 01 through 31.
dddThe abbreviated name of the day of the week.
ddddThe full name of the day of the week.
fThe tenths of a second.
ffThe hundredths of a second.
fffThe milliseconds.
hThe hour, using a 12-hour clock from 1 to 12.
hhThe hour, using a 12-hour clock from 01 to 12.
HThe hour, using a 24-hour clock from 0 to 23.
HHThe hour, using a 24-hour clock from 00 to 23.
mThe minute, from 0 through 59.
mmThe minute, from 00 through 59.
MThe month, from 1 through 12.
MMThe month, from 01 through 12.
MMMThe abbreviated name of the month.
MMMMThe full name of the month.
sThe second, from 0 through 59.
ssThe second, from 00 through 59.
tThe first character of the AM/PM designator.
ttThe AM/PM designator.
yyThe year, from 00 to 99.
yyyyThe year as a four-digit number.

Usage

require('@evokegroup/dateformat');
const date = new Date('7/8/2020 14:43');
console.log(date.toStringFormat('MMMM d, yyyy h:mm tt')); // Expected output: July 8, 2020 2:43 PM

Date.prototype.toUTCStringFormat(formatString)

Outputs a UTC Date into a string of given format. See Date.prototype.toStringFormat