JavaScript Date object provides many helpful methods for dealing with date and time. The list is so vast that it is sometimes hard for developers t...
For further actions, you may consider blocking this person and/or reporting abuse
Another approach could be to use Intl.DateTimeFormat.
The toLocaleString() method internally call the Intl’s dateFormat method.
Here is a small read about it from MDN
“ The toLocaleString() method of Date instances returns a string with a language-sensitive representation of this date. In implementations with Intl.DateTimeFormat API support, this method simply calls Intl.DateTimeFormat.”
Hence I guess it already fits the approach you suggested 😀
@atapas Agreed. I was referring to
Intl.DateTimeFormat
because it may trigger curiosity in the reader. Intl refers to internationalisation, writing for those that don't know what it is.Came for this, specially when the title says "THE BEST" 😅
intl
sure is the way to go whenever you want to fully support internationalisation and to cover all edgy cases I can think of.@joelbonetr
Oh, everyone can miss anything. Hence, comments are a great way to contribute to great posts. :-)
Sure! My bad, honestly it's hard to me nowadays to differentiate between click bait and a honest miss 😅
Of course! Comments are a great way to discuss and get better clarifications. Great to have this discussion here.
Getting a bit deeper, the toLocaleString(the best approach in this article) still uses the Intl’s date format which is already locale-aware. So, the intention was never to sound it like a clickbait one, but rather provide a solution that is far better than other older alternatives mentioned. I think, adding a few lines about the Intl will be great to avoid the confusion. What say?
I'd say yes, please. :-)
Done!
Thanks.
@atapas One small thing. Link "here" makes no sense out of the context (accessibility rule). I'd propose:
Intl.DateTimeFormat API for enabling locale-aware date-time formatting. You can read more about Intl.DateTimeFormat on MDN site.
where
Intl.DateTimeFormat on MDN site
becomes a link.More about link purpose.
Great suggestion, done 🫡
Thanks for the article!
useful
I like the array of months method. A while back I wrote a use case for using dates in Javascript without the Moment library. In this example we populate a stacked bar chart for each month (with plain vanilla js and css)
click here, then get the fully commented source code from my codepen
dev.to/rickdelpo1/how-to-populate-...
Happy coding !!