如何在 nodejs javascript mysql 中使用 1980 年 5 月 4 日星期日 00:00:00 GMT+0500(巴基斯坦标准时间)格式化日期 month/day/year

How to format the date with month/day/year from Sun May 04 1980 00:00:00 GMT+0500 (Pakistan Standard Time) in nodejs javascript mysql

这是截图中的主页代码。使用 mysql 获取该数据,它是一个带有 nodejs、express、mysql 和 bootstrap 的 CRUD 应用程序。不知道如何将日期格式化为 (month/day/year) 而不是 (Sun May 04 1980 00:00:00 GMT+0500 (Pakistan Standard Time))。请帮忙。 javascript 编程新手,所以我很挣扎:(

<div class="row">
  <div class="col-6"><h1>Users</h1></div>
  <div class="col-6 d-flex justify-content-end">
    <a href="/adduser" type="button" class="btn btn-primary align-self-center">+ add new user</a>
  </div>
</div>
<table class="table table-bordered">
  <thead class="thead-dark">
    <tr>
      <th scope="col">#</th>
      <th scope="col">First Name</th>
      <th scope="col">Last Name</th>
      <th scope="col">DoB</th>
      <th scope="col">Phone</th>
      <th scope="col" class="text-end">Action</th>
    </tr>
  </thead>
  <tbody>

    {{#each rows}}
    <tr>
      <th scope="row">{{this.id}}</th>
      <td>{{this.first_name}}</td>
      <td>{{this.last_name}}</td>
      <td>{{this.dob}}</td>
      <td>{{this.phone}}</td>
      <td class="text-end">
          <a href="/viewuser/{{this.id}}" type="button" class="btn btn-light btn-small"><i class="bi bi-eye"></i> View</a>
          <a href="/edituser/{{this.id}}" type="button" class="btn btn-light btn-small"><i class="bi bi-pencil-square"></i> Edit</a>
          <a href="/{{this.id}}" type="button" class="btn btn-light btn-small"><i class="bi bi-person-x"></i> Delete</a>
      </td>
    </tr>
    {{/each}}

  </tbody>
</table>

// View users
exports.view = (req, res) => {
    pool.getConnection((err, connection) =>{
    if(err) throw err; // not connected
    console.log('DB connected as ID' + connection.threadId);
    // User the connection
    connection.query('SELECT * FROM users ', (err, rows)=> {
    // When done with the connection, release it
    connection.release();
        if(!err){
            let removedUser = req.query.removed;
            res.render('home', { rows, removedUser });
        }
        else {
            console.log(err);
        }
        console.log('The data from user table: \n', rows);
    });
});
}

您可以在获取值时更新 SQL 查询中的日期格式。只需提及所需的日期格式并将值传递给您的视图引擎。

connection.query('SELECT all_required_columns, DATE_FORMAT(dob, "%m/%d/%y") as dob FROM users ', (err, rows)=> {

这应该从数据库中获取所有值,DOB 格式为 mm/dd/yy。
PS:北方记得