开发者

How to parse ZendGData Picasa GPhotoTimestamps in PHP

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) {
}


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!


$time = date('Y-m-d H:m:s', intval($photo->getGphotoTimestamp())/1000);


The following code worked!! cheers...

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

Happy Coding .. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜