累积日期格式
Cumulocity date formats
我想知道为什么某些字段的日期格式不同。我的规则是这样声明的:
@Name("measurement_occupation")
context ParkingSpotOccupation
insert into CreateMeasurement
select
e.source as source,
"ParkingSpotOccupation" as type,
min(e.time) as time,
{
"startDate", min(e.time),
"endDate", max(e.time),
"duration", dateDifferenceInSec(max(e.time), min(e.time))
} as fragments
from
SmartParkingEvent e
output
last when terminated;
使用 API 测量结果如下:
{
"time": "2016-05-30T06:00:00.000+02:00",
"id": "33200",
"self": "https://management.post-iot.lu/measurement/measurements/33200",
"source": {
"id": "26932",
"self": "https://management.post-iot.lu/inventory/managedObjects/26932"
},
"type": "ParkingSpotOccupation",
"startDate": {
"time": 1464580800000,
"minutes": 0,
"seconds": 0,
"hours": 6,
"month": 4,
"timezoneOffset": -120,
"year": 116,
"day": 1,
"date": 30
},
"duration": 600,
"endDate": {
"time": 1464581400000,
"minutes": 10,
"seconds": 0,
"hours": 6,
"month": 4,
"timezoneOffset": -120,
"year": 116,
"day": 1,
"date": 30
}
}
为什么吃时间和 startDate/endDate 渲染不同?更奇怪的是,当显示我的事件处理规则的输出时,它的格式如下:
{ "time": { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneOffset": -120, "year": 116 }, "source": "26932", "fragments": [ "startDate", { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneOffset": -120, "year": 116 }, "endDate", { "date": 30, "day": 1, "hours": 6, "minutes": 10, "month": 4, "seconds": 0, "time": 1464581400000, "timezoneOffset": -120, "year": 116 }, "duration", 600 ], "type": "ParkingSpotOccupation" }
所以每个日期看起来都一样,但当我使用 API 访问测量值时却不同。我希望所有日期都以这种格式存储:“2016-05-30T06:00:00.000+02:00”。我还尝试使用 cast(min(e.time), Date) 但出现错误(Class 无法加载名称 'Date' 中列出的 cast 函数)。我尝试了 toDate() 函数,但它没有任何改变。
问题在于,在 Esper 中,所有日期实际上都是 Java 中的日期 class,在解析它时,您会得到这个不太好的结构。
最简单的方法是自己将其格式化为 ISO 字符串。
您可以使用 Java SimpleDateFormat。在模块中声明它。
create constant variable SimpleDateFormat ISO_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
然后就用它
ISO_FORMATTER.format(min(e.time))
ISO_FORMATTER.format(max(e.time))
它returns日期的ISO字符串
我想知道为什么某些字段的日期格式不同。我的规则是这样声明的:
@Name("measurement_occupation")
context ParkingSpotOccupation
insert into CreateMeasurement
select
e.source as source,
"ParkingSpotOccupation" as type,
min(e.time) as time,
{
"startDate", min(e.time),
"endDate", max(e.time),
"duration", dateDifferenceInSec(max(e.time), min(e.time))
} as fragments
from
SmartParkingEvent e
output
last when terminated;
使用 API 测量结果如下:
{
"time": "2016-05-30T06:00:00.000+02:00",
"id": "33200",
"self": "https://management.post-iot.lu/measurement/measurements/33200",
"source": {
"id": "26932",
"self": "https://management.post-iot.lu/inventory/managedObjects/26932"
},
"type": "ParkingSpotOccupation",
"startDate": {
"time": 1464580800000,
"minutes": 0,
"seconds": 0,
"hours": 6,
"month": 4,
"timezoneOffset": -120,
"year": 116,
"day": 1,
"date": 30
},
"duration": 600,
"endDate": {
"time": 1464581400000,
"minutes": 10,
"seconds": 0,
"hours": 6,
"month": 4,
"timezoneOffset": -120,
"year": 116,
"day": 1,
"date": 30
}
}
为什么吃时间和 startDate/endDate 渲染不同?更奇怪的是,当显示我的事件处理规则的输出时,它的格式如下:
{ "time": { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneOffset": -120, "year": 116 }, "source": "26932", "fragments": [ "startDate", { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneOffset": -120, "year": 116 }, "endDate", { "date": 30, "day": 1, "hours": 6, "minutes": 10, "month": 4, "seconds": 0, "time": 1464581400000, "timezoneOffset": -120, "year": 116 }, "duration", 600 ], "type": "ParkingSpotOccupation" }
所以每个日期看起来都一样,但当我使用 API 访问测量值时却不同。我希望所有日期都以这种格式存储:“2016-05-30T06:00:00.000+02:00”。我还尝试使用 cast(min(e.time), Date) 但出现错误(Class 无法加载名称 'Date' 中列出的 cast 函数)。我尝试了 toDate() 函数,但它没有任何改变。
问题在于,在 Esper 中,所有日期实际上都是 Java 中的日期 class,在解析它时,您会得到这个不太好的结构。
最简单的方法是自己将其格式化为 ISO 字符串。 您可以使用 Java SimpleDateFormat。在模块中声明它。
create constant variable SimpleDateFormat ISO_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
然后就用它
ISO_FORMATTER.format(min(e.time))
ISO_FORMATTER.format(max(e.time))
它returns日期的ISO字符串