简体   繁体   中英

Date from mysql column changed after sending to front-end

I have a booking table. When I select some bookings of user SELECT * FROM booking WHERE guestId='3'; I've got:

+-----------+------------+------------+--------+---------+
| bookingId | startDate  | endDate    | roomId | guestId |
+-----------+------------+------------+--------+---------+
|         3 | 2016-04-10 | 2016-04-22 |      2 |       3 |
+-----------+------------+------------+--------+---------+

After, I send my data to front-end:

function getGuestHistory(id, res){
  dbHandler.query(`SELECT * FROM booking WHERE guestId='${id}';`, function(err, rows) {
    res.end(JSON.stringify(!err ? rows : `error: ${err}`));
  });
}

And now in front-end, when I print it console.log(res) my response is different:

[Object]
0: Object
bookingId: 3
endDate: "2016-04-21T21:00:00.000Z"
guestId: 3
roomId: 2
startDate: "2016-04-09T21:00:00.000Z"

Look, startDate and endDate was changed. For example, startDate from DB 2016-04-10 now is 2016-04-09 . Why the date is changed and how can I fix it?

Check the timezone settings in your database and on your server. These probably don't match.

The server converts the data from what is stored in the database, to what the server recognizes as it's own timezone.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM