Getting the locale date
The toLocaleDateString method on the date object lets you pass in the locale of choice and returns a string formatted date with forward slash separators.
lettoday=newDate().toLocaleDateString('en-gb');// today => 24/09/2020
Replacing the slash
To replace the forward slash with a dash is as easy as manipulating the string with a replace regex.
lettoday=newDate().toLocaleDateString('en-gb').replace(/\//g,'-');// today => 24-09-2020
Written representation
To get the written representation of the date in the chosen locale toLocaleDateString accepts a second options param where you can specify
- weekday
- year
- month
- day
constoptions={weekday:'long',year:'numeric',month:'long',day:'numeric',};lettoday=newDate().toLocaleDateString('en-gb',options);// today => Thursday, 24 September 2020
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse