如何在 PHP 中解析 ZendGData Picasa GPhotoTimestamps

发布于 2024-09-08 14:42:17 字数 949 浏览 8 评论 0原文

所以,我在这段小代码上遇到了很多麻烦。一个示例时间戳是这样的:'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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尽揽少女心 2024-09-15 14:42:17

好吧.. 事实证明,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!

网名女生简单气质 2024-09-15 14:42:17
$time = date('Y-m-d H:m:s', intval($photo->getGphotoTimestamp())/1000);
$time = date('Y-m-d H:m:s', intval($photo->getGphotoTimestamp())/1000);
无妨# 2024-09-15 14:42:17

以下代码有效!干杯...

$date_and_time = date('Y-m-d H:m:s', floatval(strval($entry->getGphotoTimestamp();)/1000));

快乐编码..:)

The following code worked!! cheers...

$date_and_time = date('Y-m-d H:m:s', floatval(strval($entry->getGphotoTimestamp();)/1000));

Happy Coding .. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文