1.0.6 • Published 6 years ago
date_time_formatter_ts v1.0.6
date_time_formatter_ts
##Description Date time formatter for typescript
Installation
$ npm install date_time_formatter_ts
Usage
import DateTimeFormatter from 'date_time_formatter_ts'
export class DateFormatTest {
constructor(private dateTimeFormatter: DateTimeFormatter) {
console.log(this.dateTimeFormatter.formatDate(new Date(), "dddd, mmmm dS, yyyy, h:MM:ss TT"));
// Saturday, June 9th, 2007, 5:46:21 PM
}
}
Format 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']
}