2

I tried to apply timezone offset to a variable. Here is my code

$time_offset = "Australia/Sydney";
$start_time = "2015-07-31 15:03:00";

$date_end = JDate::getInstance('now', $time_offset);
$date_start = JDate::getInstance($start_time, $time_offset);

echo $date_end;
echo $date_start;

$date_end is returned a correct value but $date_start returned the original value (didn't change).

Is there anything I missed here? Thanks

1

I fixed it by creating JDate object

$time_offset = "Australia/Sydney";
$start_time = "2015-07-31 15:03:00";

$date_end = JDate::getInstance('now', $time_offset);
$date_start = new JDate($start_time);
$date_start->setTimezone(new DateTimeZone($time_offset));

echo $date_end;
echo $date_start;
  • It's kinda tricky the way the DateTime class handles this - Setting the Timezone on a new date object, but at the end it does make sense. – FFrewin Sep 2 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.