将JavaScript的Date.now()转换为Stream Analytics中的时间戳
我试图通过在我的Azure物联网集线器中使用我的Raspberry Pi和Azurestream分析中的Node.js来收集压力值。 我使用以下代码将数据作为JSON文件发送给IoT Hub:
var data = JSON.stringify({ deviceId: "myRaspi10", pressureVal: value, time:Date.now() });
当我检查控制台,这是什么被发送到集线器
{ "deviceId":"myRaspi10", "pressureVal":39, "time":1470642749428 }
如何将time
值转换为Azurestream分析中的时间戳?
尝试发送new Date()
而不是Date.now()
。 它会产生一个像"2016-08-08T08:22:34.905Z"
这样的string输出,这可能是Azure Stream Analytics会像date那样对待。 (虽然没有用过,只是一个想法)。
@nobodykid,你可以使用stream分析查询语言将time
从bigint
转换为datetime
,如下所示。
CAST(time AS datetime)
请参考buildin CAST
函数和支持的转换数据types 。
根据Azurestream分析datetypes引用https://msdn.microsoft.com/en-us/library/azure/dn835065.aspx datetime表示为按照ISO 8601标准转换为datetime的string。
使用javascript Date对象并调用toSOString() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString