Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between date and time with moment.js

I have a datetimes coming back from my database in ISO format. They look like this: 2015-11-03T10:06:50.000Z. I am using moment.js to parse it out so that it's more readable and the result looks like this: 11-03-2015 10:06:50 AM. I simply want to add another space between the date and time so it's easier to read. Any thoughts?

I've tried adding another space between the date and time in moment and it appears that it strips out all spaces except one. I've also tried hyphens and pipes but those don't really look the way I want.

rows.forEach(row => {
    // TODO find a way to put more blank space between date and time
    let formattedDateTime = moment.utc(row.DateTime).format(`MM-DD-YYYY hh:mm:ss A`)
    row.DateTime = formattedDateTime
    // console.log('formatted datetime', formattedDateTime)
  })

Expected: adding spaces between the date and time in moment.format would reflect that way on the client.

Actual: only allowed one space between date and time. All other spaces are removed.

like image 456
Reese Westerhoff Avatar asked Jan 02 '23 10:01

Reese Westerhoff


1 Answers

have the same requirement, the solution is to use \xa0

moment(date).format('YYYY-MMM-DD\xa0\xa0\xa0HH:mm');

like image 189
even Avatar answered Jan 04 '23 00:01

even