0.1.3 • Published 6 years ago

print-date v0.1.3

Weekly downloads
8
License
ISC
Repository
github
Last release
6 years ago

npm version npm.io

print-date

This project forked from https://github.com/felixge/node-dateformat

  • Date, String, and Number are supported in the first argument of dateFormat.
  • Improved the pattern of the second argument of dateFormat.

Install

npm install print-date -S

Usage

The PrintDate class has default i18n values: If you need to change it, you can use the PrintDate.setI18n function to modify the custom value.

import {PrintDate, printDate} from 'print-date';

/*
PrintDate.i18n
{
    dayNames: [
      'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
      'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
    ],
    monthNames: [
      'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
      'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
    ],
    timeNames: [
      'a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'
    ]
};
*/

PrintDate.setI18n({
    dayNames: [
      'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
      'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
    ]
});
import {PrintDate, printDate} from 'print-date';

printDate('20180101', 'yy-MM-dd')
// 18-01-01
printDate('20180226', 'yyyy-M-d')
// 2018-2-26
printDate('20181225', 'MMM dd, yyyy')
// Dec 25, 2018
printDate('20181225', 'MMMM dd, yyyy')
// December 25, 2018
printDate('20181225', 'MMMM dd, yyyy(E)')
// December 25, 2018(T)
printDate('20181225', 'MMMM dd, yyyy(EE)')
// December 25, 2018(Tu)
printDate('20181225', 'MMMM dd, yyyy(EEE)')
// December 25, 2018(Tue)
printDate('20181225', 'MMMM dd, yyyy(EEEE)')
// December 25, 2018(Tuesday)
printDate('20180102152222', 'MMMM dd(EEE), yyyy. HH:mm:ss')
// January 02(Tue), 2018. 15:22:22
printDate('20180102152222', 'MMMM dd(EEE), yyyy. aa hh:mm:ss z')
// January 02(Tue), 2018. pm 03:22:22 GMT+0900
printDate('20180102152222', 'MMMM dd(EEE), yyyy. AA hh:mm:ss z')
// January 02(Tue), 2018. PM 03:22:22 GMT+0900
printDate(new Date(), 'yy-MM-dd')
// 18-02-28
printDate(new Date(), 'yyyy-M-d')
// 2018-2-28
printDate(new Date(), 'MMM dd, yyyy')
// Feb 28, 2018
printDate(new Date(), 'MMMM dd, yyyy')
// February 28, 2018
printDate(new Date(), 'MMMM dd, yyyy(E)')
// February 28, 2018(W)
printDate(new Date(), 'MMMM dd, yyyy(EE)')
// February 28, 2018(We)
printDate(new Date(), 'MMMM dd, yyyy(EEE)')
// February 28, 2018(Wed)
printDate(new Date(), 'MMMM dd, yyyy(EEEE)')
// February 28, 2018(Wednesday)
printDate(new Date(), 'MMMM dd(EEE), yyyy. HH:mm:ss')
// February 28(Wed), 2018. 16:03:38
printDate(new Date(), 'MMMM dd(EEE), yyyy. aa hh:mm:ss z')
// February 28(Wed), 2018. pm 04:03:38 GMT+0900
printDate(new Date(), 'MMMM dd(EEE), yyyy. AA hh:mm:ss z')
// February 28(Wed), 2018. PM 04:03:38 GMT+0900

let myPrintDate = new PrintDate();
myPrintDate.setDate(20180226).print('yyyy, MM, dd');

Print format description

FormatDescription
dDay of the month as digits; no leading zero for single-digit days. ex) 1
ddDay of the month as digits; leading zero for single-digit days. ex) 01
EDay of the week as a single-letter abbreviation.
EEDay of the week as a two-letter abbreviation.
EEEDay of the week as a three-letter abbreviation.
EEEEDay of the week as its full name.
MMonth as digits; no leading zero for single-digit months.
MMMonth as digits; leading zero for single-digit months.
MMMMonth as a three-letter abbreviation.
MMMMMonth as its full name.
yyYear as last two digits; leading zero for years less than 10.
yyyyYear represented by four digits.
hHours; no leading zero for single-digit hours (12-hour clock).
hhHours; leading zero for single-digit hours (12-hour clock).
HHours; no leading zero for single-digit hours (24-hour clock).
HHHours; leading zero for single-digit hours (24-hour clock).
mMinutes; no leading zero for single-digit minutes.
mmMinutes; leading zero for single-digit minutes.
NISO 8601 numeric representation of the day of the week.
oGMT/UTC timezone offset, e.g. -0500 or +0230.
sSeconds; no leading zero for single-digit seconds.
ssSeconds; leading zero for single-digit seconds.
SThe date's ordinal suffix (st, nd, rd, or th). Works well with d.
lMilliseconds; gives 3 digits.
LMilliseconds; gives 2 digits.
aLowercase, single-character time marker string: a or p.
aaLowercase, two-character time marker string: am or pm.
AUppercase, single-character time marker string: A or P.
AAUppercase, two-character time marker string: AM or PM.
WISO 8601 week number of the year, e.g. 42
zUS timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the
'...', "..."Literal character sequence. Surrounding quotes are removed.
UTC:Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.
0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.1

6 years ago