BigQuery / Node.js时间戳方式关闭 [英] BigQuery / Node.js timestamp way off

查看:170
本文介绍了BigQuery / Node.js时间戳方式关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下软件包从轻型Node.js应用程序向Google BigQuery中进行流式插入: https: //www.npmjs.org/package/bigquery



我通过这段简单的代码在服务器上生成了一个时间戳:

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

然后我将它插入BigQuery中,放入类型为'timestamp'的字段中。除了Node包之外,没有中间步骤。



但是,很多日期的日期看起来都是waaaaaay。例如:

  46343-08-28 05:58:59 UTC 

如果应该说类似于2014年5月16日下午11:45的内容。然而,我创建的一些日期是正确的,我找不到差异的原因。



有什么建议?



解决方案

检查一下:

  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

因此,要在几秒钟内获得UNIX时间戳,请将新的Date()。getTime()数字除以1000 。


Doing a streaming insert into Google BigQuery, from a light Node.js app, using this package: https://www.npmjs.org/package/bigquery

I generated a timestamp on my server via this simple line of code:

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

I then insert that into BigQuery, into a field with type 'timestamp'. There is no intermediate step (besides the Node package).

But many, although not all, of dates look waaaaaay off. For example:

46343-08-28 05:58:59 UTC

When that should say something like 11:45pm on 05-16-2014. However, some of my createdAt dates are correct, and I can't find a reason for the difference.

Any suggestions?

解决方案

Without actually debugging the JS code, this seems to be an "off by a thousand" problem.

Check this out:

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 a UNIX timestamp in seconds, divide the new Date().getTime() number by 1000.

这篇关于BigQuery / Node.js时间戳方式关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆