【发布时间】:2014-08-18 12:48:25
【问题描述】:
我正在尝试使用Google API PHP Client 将日期值存储在 Google 数据存储区中,但服务总是以错误回复:
无效值:无效格式:“2014-08-18 12:40:52”在“12:40:52”处格式错误。
这是我使用的代码中有趣的部分:
function create_entity($name, $property, $data) {
$entity = new Google_Service_Datastore_Entity();
$entity->setKey(createKey($name));
$string_prop = new Google_Service_Datastore_Property();
$string_prop->setStringValue($data);
$string_prop->setIndexed(false);
$time = date("Y-m-d H:i:s");
$string_date = new Google_Service_Datastore_Property();
$string_date->setDateTimeValue($time);
$string_date->setIndexed(false);
$property_map = [];
$property_map[$property] = $string_prop;
$property_map['date'] = $string_date;
$entity->setProperties($property_map);
return $entity;
}
function create_commit($name, $property, $data) {
$entity = create_entity($name, $property, $data);
$mutation = new Google_Service_Datastore_Mutation();
$mutation->setUpsert([$entity]);
$req = new Google_Service_Datastore_CommitRequest();
$req->setMode('NON_TRANSACTIONAL');
$req->setMutation($mutation);
return $req;
}
【问题讨论】:
标签: php google-app-engine google-cloud-datastore