Skip to content

Instantly share code, notes, and snippets.

@elmasse
Created December 6, 2017 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmasse/1fcc35dea402c6df5040f010cf6f3678 to your computer and use it in GitHub Desktop.
Save elmasse/1fcc35dea402c6df5040f010cf6f3678 to your computer and use it in GitHub Desktop.
new Date(post.data.date).toLocaleString(format.locale, format.options)
Use toLocaleDateString();
The toLocaleDateString() method returns a string with a language-sensitive representation of the date portion of the date. The locales and options arguments let applications specify the language whose formatting conventions should be used and allow to customize the behavior of the function.
The values you can passed in options for different keys:
day:
The representation of the day.
Possible values are "numeric", "2-digit".
weekday:
The representation of the weekday.
Possible values are "narrow", "short", "long".
year:
The representation of the year.
Possible values are "numeric", "2-digit".
month:
The representation of the month.
Possible values are "numeric", "2-digit", "narrow", "short", "long".
hour:
The representation of the hour.
Possible values are "numeric", "2-digit".
minute: The representation of the minute.
Possible values are "numeric", "2-digit".
second:
The representation of the second.
Possible values are "numeric", 2-digit".
All these keys are optional.You can change the number of options values based on your requirements.
For different languages:
"en-US": For English
"hi-IN": For Hindi
"ja-JP": For Japanese
You can use more language options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment