简体   繁体   English

从MySQL解析时转换的日期时间值

[英]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.

相关问题 转换为Python日期时间后,Node的时间戳落后3分钟 - Timestamp from Node is 3 minutes behind when converted to Python datetime 来自已解析 DateTime 的错误 unix 时间 - Wrong unix time from parsed DateTime 在Java中将哈希图的哈希图转换为json。 当发送到jsp时,我在javascript中对其进行了解析。 但是在javascript中没有正确解析 - Hashmap of hashmaps converted to json in java. When sent to jsp, i parsed it in javascript. But it is not parsed correct in javascript 数组中的JSON无法正确解析 - JSON from array not being parsed correctly 防止反斜杠被javascript解析为字符串 - Prevent backslash from being parsed by javascript for a string 来自 web api 的值没有被转换 - Values from web api are not being converted 阻止颜色转换为RGB? - Keep colors from being converted to RGB? 尽管使用了“=”,属性值仍被解析为指令中的字符串 - Attribute value being parsed as string in directive despite using “=” 打印时会解析角度值,但不会将其作为指令属性进行解析 - Angular value is parsed when printed, but not as a directive attribute 与以下内容一起解析时,第一个值返回“ undefined” - First value returns “undefined” when parsed with the following
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM