I have an array like this:
const myArray = [
{ title: "one", location: "one", start_date_time: "2023-06-28T08:47:00.000Z" },
{ title: "two", location: "two", start_date_time: "2023-06-28T08:47:00.000Z" }
]
I need the each objects start date to be formatted into something more readable, while maintaining the arrays structure. Something like "yyyy MM dd hh:mm", so removing dashes, the T, and the seconds.
How do I either update my existing array with formatted date and time, or create a new array with the correct formatting?
4
Answers
You could simply just find and replace.
You can achieve this by using map method in JavaScript.
Here, is the sample code for it.
Link: https://codesandbox.io/s/javascript-forked-gfkhr7?file=/index.js
@Jamiec‘s answer was almost perfect but missing the removal of the time after minutes, so just added a .slice().
Hello here is a way of doing it with native javascript :
here is a working sand box https://codesandbox.io/s/unruffled-flower-cqdqr3?file=/src/index.js:0-556