npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

date-stringifier

v2.0.0

Published

Format your date into a string however you like.

Downloads

245

Readme

Date Stringifier

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:

  • YearsMonthsDays
  • HoursMinutesSecondsMilliseconds
  • TimezoneOthers

| Syntax | Description | Result | | :------: | ----------- | ------ | |Years| | yyyy | Full Year. | 1995, 2022... | yy | Just the last 2 digits of the Year. | 95, 22... | yyrel | The relative time in years compared to now. | 1 year ago, in 10 years... |Months| | month | Month's name.| January, February...| | MM | Month's number. | 1, 2... 10, 11, 12. | zMM | Month's number, with a zero if it is below 10. | 01, 02... 10, 11, 12. | MMrel | The relative time in months compared to now. | 1 month ago, in 10 months... |Days| | day | Name of the day of the week.|Sunday, Monday... | DDs | Corresponding day of the week, starting on Sunday. | 1, 2, 3, 4, 5, 6 or 7. | DDm | Corresponding day of the week, starting on Monday. | 1, 2, 3, 4, 5, 6 or 7. | DD | Day of the month. | 1, 2... 28, 29, 30... | zDD | Day of the month, with a zero if it is below 10. | 01, 02... 28, 29, 30... | oDD | Ordinal day of the month. | 1st, 2nd, 3rd... 29th, 30th... | DDrel | The relative time in days compared to now. | 1 day ago, in 10 days... |Hours| | hour | Hour in 24:00 format through text. | One, Two... Twenty-three, Twenty-four. | hh | Hour in 24:00 format. | 1, 2... 22, 23, 0. | zhh | Hour in 24:00 format, with a zero if it is below 10. | 01, 02... 22, 23, 00. | hour12 | Hour in 12:00 format through text. | One, Two... Eleven, Twelve. | hh12 | Hour in 12:00 format. | 1, 2... 11, 12, 1. | zhh12 | Hour in 12:00 format, with a zero if it is below 10. | 01, 02... 11, 12, 01. | hhp | The 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. | hhrel | The relative time in hours compared to now. | 1 hour ago, in 10 hours... |Minutes| | minute | Minute through text. | One, Two... Fifty-eight, Fifty-nine. | mm | Minutes. | 1, 2... 58, 59. | zmm | Minutes, with a zero if it is below 10. | 01, 02... 58, 59. | mmrel | The relative time in minutes compared to now. | 7 minutes ago, in 150 minutes... |Seconds| | second | Second throught text. | One, Two... Fifty-eight, Fifty-nine. | ss | Seconds. | 1, 2... 58, 59. | zss | Seconds, with a zero if it is below 10. | 01, 02... 58, 59. | ssrel | The relative time in seconds compared to now. | 7 seconds ago, in 15000 seconds... |Milliseconds| | ms | Milliseconds. | 0, 1... 998, 999. |Timezone| | tz | The difference in minutes between UTC+0. | ...-120, -60, 0, 60, 120... | utc | The difference in hours between UTC+0. | ...-2, -1, +0, +1, +2... |Others| | unixms | How many seconds have passed since January 1st of 1970, including milliseconds. | 1610309753427, 1646932270794... | unix | How many seconds have passed since January 1st of 1970. | 1610309753, 1646932270... | rel | The relative date time compared to now. | 7 seconds ago, in 2 hours, 10 days ago... | century | The dates century. | 19, 20, 21...

🐉 Info

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

Created by Nick Gabe.