开发者

How to not have moment.js convert dates

开发者 https://www.devze.com 2022-12-07 18:30 出处:网络
I have a node.js program, which uses the oracledb package. It 开发者_C百科connects to an Oracle database, selects data and stores that data into another Oracle database.

I have a node.js program, which uses the oracledb package.

It 开发者_C百科connects to an Oracle database, selects data and stores that data into another Oracle database.

Both databases are configured for UTC for storing date/time values

Here is a code snippet:

 let sql = `
              SELECT 
                 a.*
              FROM
                 some_view a
           `;

        const result = await db1.execute(
            sql,
            {},
            {
                outFormat: oracledb.OUT_FORMAT_OBJECT
            }
        );

        const workOrders= result.rows as WorkOrder[];
        .
        .
        for (const workOrder of workOrders) {
            await db2.execute(
                `
             INSERT INTO table(workordernumber, startdate) VALUES (:workordernumber, :startdate),
             {
                workordernumber: workOrder.workordernumber,
                startdate: startdate
              },
        );
  

The problem is that the date/time values are being converted to my local time zone when stored in the destination system.

I am in EST. So, 09/07/2022 17:04:08 from the source is stored as 09/07/2022 22:04:08 in the destination.

I have tried using moment, without success, to prevent the conversion on the destination as follows:

  INSERT INTO table(workordernumber, startdate) VALUES (:workordernumber, :startdate),
             {
                workordernumber: workOrder.workordernumber,
                startdate: moment.utc(startdate)
              },

The values are still converted to my local time zone.

I want to take the UTC values from one database and store them as UTC values in other, without any conversion.

Any suggestions?

0

精彩评论

暂无评论...
验证码 换一张
取 消