将 Javascript 的 Date.now() 转换为流分析中的时间戳

converting Javascript's Date.now() into timestamp in Stream Analytics

我尝试使用 Raspberry Pi 中的 Node.js 和 Azure IoT 中心中的 Azure 流分析来收集压力值。我使用以下代码将数据作为 JSON 文件发送到 IoT 中心:

var data = JSON.stringify({ 
               deviceId: "myRaspi10",
               pressureVal: value, 
               time:Date.now() 
           });

当我检查控制台时,这是发送到集线器的内容

{
    "deviceId":"myRaspi10",
    "pressureVal":39,
    "time":1470642749428
}

如何在 Azure 流分析中将 time 值转换为时间戳?

根据 Azure 流分析日期类型参考 https://msdn.microsoft.com/en-us/library/azure/dn835065.aspx 日期时间表示为按照 ISO 8601 标准转换为日期时间的字符串。

使用javascript 日期对象并调用 toISOString() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

@nobodykid,您可以使用 Stream Analyics Query Languagetimebigint 转换为 datetime,如下所示。

CAST(time AS datetime)

请参考内置CAST function and the supported data types进行转换。

尝试发送 new Date() 而不是 Date.now()。它会产生一个字符串输出,如 "2016-08-08T08:22:34‌​.905Z",这可能是 Azure 流分析会像日期一样对待。 (虽然没用过,只是一个想法)。