views:

21

answers:

2

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) {
}
A: 
$time = date('Y-m-d H:m:s', intval($photo->getGphotoTimestamp())/1000);
:) nice try but this is exactly what I meant when I said I knew about the milliseconds problem.. Here are 2 screenshots to show you I at least tried it .. Code: http://moby.to/lcbclk DB: http://moby.to/tu0zh0 ... thanks for trying though!
1) Try intval($photo->getGphotoTimestamp())/1000) instead of floatval($photo->getGphotoTimestamp()/1000))2) User intval instead of flaotval
:/ actually that was a suggestion made by a colleague.. i've tried both now and both don't give the correct answer..
A: 

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!