如何在 PHP 中解析 ZendGData Picasa GPhotoTimestamps
所以,我在这段小代码上遇到了很多麻烦。一个示例时间戳是这样的:'1278509422000'..问题是它作为字符串出现,我必须以某种方式转换它。我知道毫秒的问题,并尝试除以 1000 甚至更多(intval/floatval),但它不会成为正确的日期时间值。
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
$gp = new Zend_Gdata_Photos(Zend_Gdata_AuthSub::getHttpClient($data->token), "Bla");
try {
$userFeed = $gp->getUserFeed("default");
foreach ($userFeed as $userEntry) {
$album = $userEntry->getGphotoName();
try {
$query = $gp->newAlbumQuery();
$query->setUser("default");
$query->setAlbumName($album);
$albumFeed = $gp->getAlbumFeed($query);
foreach ($albumFeed as $photo) {
$time = date('Y-m-d H:m:s', $photo->getGphotoTimestamp());
}
} catch(Exception $e) {
}
}
} catch(Exception $e) {
}
So, i'm having a lot of trouble with this little piece of code. An example timestamp is this: '1278509422000'.. the problem is that it comes in as a string and I have to convert it somehow. I know about the problem with milliseconds and have tried dividing by a 1000 and much more (intval/floatval) but it just will not become a correct datetime value.
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
$gp = new Zend_Gdata_Photos(Zend_Gdata_AuthSub::getHttpClient($data->token), "Bla");
try {
$userFeed = $gp->getUserFeed("default");
foreach ($userFeed as $userEntry) {
$album = $userEntry->getGphotoName();
try {
$query = $gp->newAlbumQuery();
$query->setUser("default");
$query->setAlbumName($album);
$albumFeed = $gp->getAlbumFeed($query);
foreach ($albumFeed as $photo) {
$time = date('Y-m-d H:m:s', $photo->getGphotoTimestamp());
}
} catch(Exception $e) {
}
}
} catch(Exception $e) {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧.. 事实证明,ZendGData 是非常面向对象的,函数 getGphotoTimestamp() 返回一个对象而不是时间戳。我没有注意到这一点,因为代码在项目中(在 gearman 工作中)位置偏僻,而且该对象实现了 __toString() ,它返回时间戳的字符串代表!使用 floatval( strval( ... ) ) 就可以了!
Ok.. So as it turns out, ZendGData is very very object oriented and the function getGphotoTimestamp() returns an object instead of and timestamp. I did not notice this because of the out-of-the way place the code has in the project (in a gearman job) and the fact that the object implements a __toString() which returns the string rep of the timestamp! Using floatval( strval( ... ) ) did the trick!
以下代码有效!干杯...
快乐编码..:)
The following code worked!! cheers...
Happy Coding .. :)