I am trying to format a date that is being requested from my database. I looked up how to format date and I got this as a solution:
var d = new Date("2015/03/25");
Which would work, but my date is stored in a data object and it's a different date for every row (since the data from the DB is being displayed in a table.
let DateSubmitted = new Date(**data[i].DateSubmitted)**;
list += `
<tr>
<td class="requestID">${data[i].requestID}</td>
<td class="date-requested">**${DateSubmitted}**</td>
<td class="item-code">${data[i].itemCode}</td>
...
My question is, how do I format each date returned from data[i] ?
Thanks!
ES5:
var dateFormatted = DateSubmitted.getDate() + '/' + (DateSubmitted.getMonth() + 1) + '/' + DateSubmitted.getFullYear();
ES6:
const dateFormatted = `${DateSubmitted.getDate()}/${DateSubmitted.getMonth() + 1}/${DateSubmitted.getFullYear()}`
So,
let DateSubmitted = new Date(**data[i].DateSubmitted)**;
const dateFormatted = `${DateSubmitted.getDate()}/${DateSubmitted.getMonth() + 1}/${DateSubmitted.getFullYear()}`
list += `
<tr>
<td class="requestID">${data[i].requestID}</td>
<td class="date-requested">**${dateFormatted}**</td>
<td class="item-code">${data[i].itemCode}</td>
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.