Firestore PHP SDK-如何保存日期



我尝试在firestore中保存日期,但每次都像字符串或数字一样保存,我需要保存为时间戳

date( 'U', strtotime( '-4 HOUR' ) ); // result something like 1605958160

PHP 示例

$docRef = $db->collection('users')->document('lovelace');
$docRef->set([
'first' => 'Ada',
'last' => 'Lovelace',
'born' => date( 'U', strtotime( '-4 HOUR' ) )
]);

关注@RiggsFolly提供的信息我发现了Github谷歌云平台的这些信息如何将时间戳添加到firestore

只需使用

new DateTime('2000-01-01', new DateTimeZone('America/Sao_Paulo'));

感谢

最新更新