BigQuery / Node.js timestamp way off

Performing a paste in Google BigQuery from a lightweight Node.js application using this package: https://www.npmjs.org/package/bigquery

I created a timestamp on my server through this simple line of code:

jsonData['createdAt'] = new Date().getTime(); 

Then I insert this into BigQuery in a field of type timestamp. There is no intermediate step (except for the Node package).

But many, though not all, dates look waaaaaay. For instance:

 46343-08-28 05:58:59 UTC 

When it should say something like 11:45 pm 05-16-2014. However, some of my created dates are correct, and I cannot find the reason for the difference.

Any suggestions?

+3
source share
1 answer

Without actually debugging the JS code, this seems like a "thousand" problem.

Check this:

 SELECT USEC_TO_TIMESTAMP(1400341611711851) 2014-05-17 15:46:51 UTC SELECT USEC_TO_TIMESTAMP(1400341611711851*1000) 46345-01-22 13:01:51 UTC SELECT MSEC_TO_TIMESTAMP(1400341611711851) 46345-01-22 13:01:51 UTC SELECT MSEC_TO_TIMESTAMP(1400341611711851/1000) 2014-05-17 15:46:51 UTC 

So, to get the UNIX timestamp in seconds, divide the number of new Date().getTime() by 1000.

+7
source

Source: https://habr.com/ru/post/1201155/


All Articles