停止自动转换时区

时间:2018-10-25 10:41:03

标签: javascript node.js

Java脚本会自动转换时区,如何停止时区?

我创建了一个api,该api从mysql表中获取数据并将其显示为json格式,但是问题是,除了datetime列之外,其他所有东西都保持预期。 仅时间戳字段(DateTime Columns)自动更改了为什么?

Mysql存储过程输出

enter image description here

JsonResponse

[
    {
        "OrderId": 2164294,
        "MRP": 270,
        "LedId_Party": "757",
        "ItemDetailId": "10000196",
        "NAME": "Retail Graph Admin",
        "OrderNo": "RTG7",
        "OrderDate": "2018-10-25T11:31:29.896Z",
        "Qty": 15,
        "Remarks": "test order",
        "CompanyId": " R01142\\d",
        "OtherPartyCode": "757",
        "PartyName": "Tanaya das",
        "OtherProductCode": "10000196",
        "ProductName": "ROLIFLO OD CAP 404 10S",
        "Company": "RANBAXY  RESPIRATORY",
        "Packing": "10S",
        "Free": 1,
        "CreatedDate": "2018-10-25T11:31:29.896Z",
        "Scheme": null,
        "PTR": 0,
        "Delivery": 1,
        "SalesmanCode": null,
        "DeliveryMode": "To Deliver",
        "ProductRemarks": null,
        "SchemeType": null
    },
    {
        "OrderId": 2164294,
        "MRP": 198.25,
        "LedId_Party": "757",
        "ItemDetailId": "10000426",
        "NAME": "Retail Graph Admin",
        "OrderNo": "RTG7",
        "OrderDate": "2018-10-25T11:31:29.896Z",
        "Qty": 20,
        "Remarks": "PR:test product GR:test order",
        "CompanyId": " R01142\\d",
        "OtherPartyCode": "757",
        "PartyName": "Tanaya das",
        "OtherProductCode": "10000426",
        "ProductName": "BAKFLEX 8MG 10S",
        "Company": "INTAS[ARRON]9332940350[SUMAN]",
        "Packing": "10S",
        "Free": 0,
        "CreatedDate": "2018-10-25T11:31:29.896Z",
        "Scheme": null,
        "PTR": 0,
        "Delivery": 1,
        "SalesmanCode": null,
        "DeliveryMode": "To Deliver",
        "ProductRemarks": "test product",
        "SchemeType": null
    }
]

节点代码:

app.get('/Admin/api/GetPurchaseOrderToUpload', async (req, res) => {
        const jsonobject = await objPurchaseOrder.GetPurchaseOrderToUpload(DecryptedDistributorCode);
        return res.status(200).json(jsonobject);
    });

PurchaseOrder.js

var pool =  require('../models/poolconnection');
// const mongoose = require('mongoose');
function GetPurchaseOrderToUpload(DistributorCode) {
    return new Promise((resolve,reject) => {
        var query = 'call PR_GetPurchaseOrderToUpload(?)';
        pool.query(query,[DistributorCode],(err,result,fields) => {
            if(err) reject(err);
            else {
                resolve(result[0]);
            }
        });
    });
}
module.exports = {
    GetPurchaseOrderToUpload: GetPurchaseOrderToUpload,
 }

2 个答案:

答案 0 :(得分:0)

Json响应是从Web API(节点应用程序)生成的。可能您应该在服务器级别本身坚持一个时区或UTC时区。您可以使用moment.tz将日期时间转换为特定时区,这确实很有帮助。

  

https://momentjs.com/timezone/

答案 1 :(得分:0)

仅需将mysql连接的dateStrings属性设置为true

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'example.org',
  user     : 'bob',
  password : 'secret',
  dateStrings : true
});