2.0.0 β€’ Published 2 years ago

date-stringifier v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Date Stringifier

npm.io npm.io npm.io

Date Stringifier is a package created exclusively for Date Formatting. Trying to be simple and direct as possible.

πŸš€ How To install:

npm install date-stringifier

πŸ“š How to use:

First you will need to import the package.

Then you can use it as a function, passing a Date created using the Date Constructor, and how you want the formatted output to be. You can use Date variables in your string, as shown in the example below:

const dateStringifier = require('date-stringifier')
const date = new Date(1995, 11, 17)

console.log(dateStringifier(date, '{DD}/{MM}/{yyyy}'))
// It will print 17/12/1995
// *Months are zero indexed, so it adds one

You can also specify the language you want the result to be, if you don't specify, it will be set to English by default. The available languages are:

  • en - English
  • pt - Portuguese
const date = new Date()
const english = dateStringifier(date, 'Today is the {oDD} day of {month}', 'en')
// Today is the 25th day of June
const portuguese = dateStringifier(date, 'Hoje Γ© o {oDD} dia de {month}', 'pt')
// Hoje Γ© o 25ΒΊ dia de Junho

Date variables are the ones you use to insert something based on the date you passed to the function. For example, every {yyyy} in your string will be replaced by the Date's year (1995).

Any text that is not between brackets "{}" will not be considered as a variable, therefore it won't change in the final result.

These are the Date variables you can use in your string:

*They are case-sensitive.

Menu:

  • Years β€’ Months β€’ Days
  • Hours β€’ Minutes β€’ Seconds β€’ Milliseconds
  • Timezone β€’ Others
SyntaxDescriptionResult
Years
yyyyFull Year.1995, 2022...
yyJust the last 2 digits of the Year.95, 22...
yyrelThe relative time in years compared to now.1 year ago, in 10 years...
Months
monthMonth's name.January, February...
MMMonth's number.1, 2... 10, 11, 12.
zMMMonth's number, with a zero if it is below 10.01, 02... 10, 11, 12.
MMrelThe relative time in months compared to now.1 month ago, in 10 months...
Days
dayName of the day of the week.Sunday, Monday...
DDsCorresponding day of the week, starting on Sunday.1, 2, 3, 4, 5, 6 or 7.
DDmCorresponding day of the week, starting on Monday.1, 2, 3, 4, 5, 6 or 7.
DDDay of the month.1, 2... 28, 29, 30...
zDDDay of the month, with a zero if it is below 10.01, 02... 28, 29, 30...
oDDOrdinal day of the month.1st, 2nd, 3rd... 29th, 30th...
DDrelThe relative time in days compared to now.1 day ago, in 10 days...
Hours
hourHour in 24:00 format through text.One, Two... Twenty-three, Twenty-four.
hhHour in 24:00 format.1, 2... 22, 23, 0.
zhhHour in 24:00 format, with a zero if it is below 10.01, 02... 22, 23, 00.
hour12Hour in 12:00 format through text.One, Two... Eleven, Twelve.
hh12Hour in 12:00 format.1, 2... 11, 12, 1.
zhh12Hour in 12:00 format, with a zero if it is below 10.01, 02... 11, 12, 01.
hhpThe hour period, returns AM if it is between 00:00-11:59 and PM if it is between 12:00-23:59.AM or PM.
hhrelThe relative time in hours compared to now.1 hour ago, in 10 hours...
Minutes
minuteMinute through text.One, Two... Fifty-eight, Fifty-nine.
mmMinutes.1, 2... 58, 59.
zmmMinutes, with a zero if it is below 10.01, 02... 58, 59.
mmrelThe relative time in minutes compared to now.7 minutes ago, in 150 minutes...
Seconds
secondSecond throught text.One, Two... Fifty-eight, Fifty-nine.
ssSeconds.1, 2... 58, 59.
zssSeconds, with a zero if it is below 10.01, 02... 58, 59.
ssrelThe relative time in seconds compared to now.7 seconds ago, in 15000 seconds...
Milliseconds
msMilliseconds.0, 1... 998, 999.
Timezone
tzThe difference in minutes between UTC+0....-120, -60, 0, 60, 120...
utcThe difference in hours between UTC+0....-2, -1, +0, +1, +2...
Others
unixmsHow many seconds have passed since January 1st of 1970, including milliseconds.1610309753427, 1646932270794...
unixHow many seconds have passed since January 1st of 1970.1610309753, 1646932270...
relThe relative date time compared to now.7 seconds ago, in 2 hours, 10 days ago...
centuryThe dates century.19, 20, 21...

πŸ‰ Info

This package is open source, feel free to contribute through GitHub.

Created by Nick Gabe.

1.1.1

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

2.0.0

2 years ago

1.1.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago