如何在 Orion 中存储时间戳或日期时间?
How do I store timestamp or datetime in Orion?
我正在使用 Orion 来存储上下文信息,在所有实体属性中,有两个是特定于时间的:
- updated_at
- created_at
我该如何存储它? Orion 中是否有时间戳或日期时间属性类型?
您可以使用属性类型 date
来存储日期,如 NGSIv2 specification 部分 "Special attribute types" 中所述。例如,您可以创建以下实体:
POST /v2/entities
{
"id": "myEntity",
"type": "myType",
"updated_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
},
"created_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
}
}
请注意(至少在最新的 Orion 版本 0.28.0 中)精度为秒。换句话说,你可以 create/update 和 2017-06-17T07:21:24.238Z
但你会得到 2017-06-17T07:21:24.00Z
.
另请注意,Orion 会自动管理实体的创建和修改日期,即您的客户不需要管理它们。为了检索实体创建 and/or 修改,请在 options
URI 参数中使用它们,如 NGSIv2 specification 部分 "Virtual attributes" 中所述。例如:
GET /v2/entities/myEntity?options=dateCreated,dateModified
我正在使用 Orion 来存储上下文信息,在所有实体属性中,有两个是特定于时间的:
- updated_at
- created_at
我该如何存储它? Orion 中是否有时间戳或日期时间属性类型?
您可以使用属性类型 date
来存储日期,如 NGSIv2 specification 部分 "Special attribute types" 中所述。例如,您可以创建以下实体:
POST /v2/entities
{
"id": "myEntity",
"type": "myType",
"updated_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
},
"created_at": {
"value": "2017-06-17T07:21:24.00Z",
"type": "date"
}
}
请注意(至少在最新的 Orion 版本 0.28.0 中)精度为秒。换句话说,你可以 create/update 和 2017-06-17T07:21:24.238Z
但你会得到 2017-06-17T07:21:24.00Z
.
另请注意,Orion 会自动管理实体的创建和修改日期,即您的客户不需要管理它们。为了检索实体创建 and/or 修改,请在 options
URI 参数中使用它们,如 NGSIv2 specification 部分 "Virtual attributes" 中所述。例如:
GET /v2/entities/myEntity?options=dateCreated,dateModified