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
  • JDate extends PHP's DateTime class and this behavior is inherited from the parent class and not from JDate.
    – FFrewin
    Sep 1, 2015 at 22:20

1 Answer 1

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;
1
  • 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, 2015 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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