datetime-str
v1.0.2
Published
Converts Date object to string with some format
Downloads
6
Maintainers
Readme
Installation
Open your project's directory and execute next command:
npm install --save datetime-str
Including to your project
In order to use package in your project it should be assigned to the variable
const datetime_str = require('datetime-str');
Next command will create variable datetime_str that will hold module
Structure
monthNames
- Names of months starting from JanuarymonthNamesPart
- Contains first 3 symbols of each month namedayNames
- Names of days of week starting from SundaydayNamesPart
- Contains first 3 symbols of each day nameformats
- Contains list of standart patternsformat(pattern, date)
- Creates string by pattern using given date
API
monthNames
- names of months from January
Type: array
Length: 12
Values:
[
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
monthNamesPart
- first 3 symbols of months names
Type: array
Length: 12
Values:
[
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
]
dayNames
- Names of days of week starting from Sunday
Type: array
Length: 7
Values:
[
'Sunday',
'Monday',
'Tuesday',
'Wednessday',
'Thursday',
'Friday',
'Saturday'
]
dayNamesPart
- first 3 symbols of day names
Type: array
Length: 7
Values:
[
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat'
]
formats
- Contains list of standart patterns
Type: object
Keys: default, en, ru
default format
{
'full' : '{yyyy mmmm d HH:MM:SS} UTC {UTC}',
'datetime' : '{yyyy-mm-dd HH:MM:SS}',
'datetime12' : '{yyyy-mm-dd HH12:MM:SS AMPM}',
'date' : '{yyyy-mm-dd}',
'time' : '{HH:MM:SS}',
'time12' : '{HH12:MM:SS AMPM',
'precise' : 'SS.LL'
}
us format
{
'full' : '{mmmm d yyyy HH:MM:SS} UTC {UTC}',
'datetime' : '{mm/dd/yyyy HH:MM:SS}',
'datetime12' : '{mm/dd/yyyy HH12:MM:SS ampm}',
'date' : '{mm/dd/yyyy}'
}
ru format
{
'full' : '{yyyy mmmm d HH:MM:SS} UTC {UTC}',
'datetime' : '{dd.mm.yyyy HH:MM:SS}',
'datetime12' : '{dd.mm.yyyy HH12:MM:SS ampm}',
'date' : '{dd.mm.yyyy}'
}
Formating
format(pattern, date)
- Formats date using pattern
pattern
- string
date
- standart Date object
Starting with patterns
Pattern is a simple string that can contains any symbols
To designate where formated date should be placed {}
(curly braces) are used
Simple pattern that shows current time will be:
'Current time is {HH} hours {MM} minutes {SS} seconds'
It is possible to use multiple keys within {}
(curly braces)
'Current time: {HH:MM:SS}`
They can be splited by any not alpha-numeric symbols
List of possible keys
Date - numbers
yyyy
- full year. Example: 2002
yy
- two-digit year with leading zero. Example: 02
y
- two-digit year without leading zero. Example: 2
mm
- month with leading zero
m
- month without leading zero
dd
- day with leading zero
d
- day without leading zero
Date - strings
mmmm
- Month name. Full form
mmm
- Month name. Only first 3 symbols
dddd
- Day of week. Full form
ddd
- Day of week. Only first 3 symbols
Time
HH24
- 24 hours time with leading zero
HH
- 24 hours time with leading zero. Shortcut
HH12
- 12 hours time with leading zero. Should be used together with ampm
H24
- 24 hours time without leading zero
H
- 24 hours time without leading zero. Shortcut
H12
- 12 hours time without leading zero. Should be used together with ampm
MM
- Minutes with leading zero
M
- Minutes without leading zero
SS
- Seconds with leading zero
S
- Seconds without leading zero
LL
- Milliseconds with leading zero
L
- Milliseconds without leading zero
Special
ampm
- Current half of the day as am
or pm
AMPM
- Current half of the day as AM
or PM
UTC
- Time zone offset. Example +1 or -2:30