Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  126] [ 3]  / answers: 1 / hits: 8750  / 5 Years ago, fri, september 20, 2019, 12:00:00

I want to display dates (range of dates). The format of dates coming from DB seperated by hyphen is




Sep 21, 2017 - Sep 29, 2017




I want to convert it to the format




09/21/2017 - 09/25/2017




How can I convert this?


More From » reactjs

 Answers
5

You can use this function that converts to your format:
Your CodeSand





const convert = dateRange =>
dateRange.split( - )
.map(date => new Intl.DateTimeFormat('en-US').format(new Date(date)))
.join( - )

console.log(convert(Sep 21, 2017 - Sep 29, 2017));





The code below works and uses only pure JavaScript ES6.


[#6190] Wednesday, September 18, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
travion

Total Points: 137
Total Questions: 96
Total Answers: 103

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
travion questions
Mon, Dec 16, 19, 00:00, 5 Years ago
Sat, Oct 19, 19, 00:00, 5 Years ago
Wed, Nov 14, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
;