[英]Datetime value being converted when parsed from MySQL
I have a problem here. 我在这里有问题。 I have a MySQL database with datetime field which has format: '2016-12-31 21:59:59'.
我有一个带有日期时间字段的MySQL数据库,其日期格式为:'2016-12-31 21:59:59'。 I am fetching this value in nodejs and pass it to the table, but in table it has format: Sat Dec 31 2016 21:59:59 GMT+0200 (EET) why does this happen and how I can make it so it is '2017-01-01 23:59:59' in the table too?
我正在nodejs中获取此值并将其传递到表中,但在表中它具有以下格式:Sat Dec 31 2016 21:59:59 GMT + 0200(EET)为什么会发生这种情况以及如何使它成为' 2017-01-01 23:59:59'也放在桌子上吗?
This is how I fetch it: 这是我的获取方式:
connection.query("SELECT * FROM TestInformation", function (err, rows, fields) {
if (err) {
console.log('Bad query!');
console.log(err);
}
else {
console.log('Successful query!');
//console.log(rows);
information = rows;
res.render('index', {information: information});
}
});
And this is how I use it: 这就是我的用法:
<input type="text" id="last_measure" placeholder="Last Measure" name="last_measure"
class="form-control" value="{{information.0.Last_Measure}}">
Change the query like the following: 如下更改查询:
"SELECT *, DATE_FORMAT(dateColumn, '%Y-%m-%d %H:%i:%s') as dateColumn FROM TestInformation"
Using the above query, you can change the date format of the dateColumn
to represent in console. 使用上面的查询,您可以更改
dateColumn
的日期格式以在控制台中表示。
I should have mentioned that, this format is the default format of storing Timestamp in MySQL, and what you see is the format of representation in your application. 我应该提到的是,这种格式是在MySQL中存储时间戳的默认格式,而您所看到的就是应用程序中表示的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.