1

My time zone is Europe/Rome. I'm using Facebook PHP SDK and insights part of the API accepts a parameter end_time relative to Pacific Daylight Time:

The end of the period during which the metrics were collected, expressed as a unix time (which should always be midnight, Pacific Daylight Time).

Question is fair simple: should i convert $end to PDT (and how) before calling getTimeStamp() in order to get correct stats for my time zone?

// Get stats with 1st January 2012 as end_time (relative to my time zone)
$page  = Facebook->getUser()->getPage($id);
$stats = $page->getData('page_views_unique', new DateTime('2012-01-01')); 

public function getData($metric, DateTime $end = null)
{
   $now = new DateTime();
   $end = is_null($end) || $end > $now ? $now : $end; // Default is $now

   // API call
   $args = array('end_time' => $end->getTimestamp());
   $this->sdk->api(sprintf('/%s/insight/%s', $this->id, $metric), 'GET', $args);
}
hakre
  • 193,403
  • 52
  • 435
  • 836

1 Answers1

0

Convert time and date from one time zone to another in PHP

<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Europe/Rome'));
echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('America/Los_Angeles'));
echo $date->format('Y-m-d H:i:sP') . "\n";
?>
Community
  • 1
  • 1
DMCS
  • 31,720
  • 14
  • 71
  • 104