Home Forums General Issues Timezone confusion over ACF DateTime picker


Timezone confusion over ACF DateTime picker

  • Hey folks, thank you for such a great plugin.

    In my custom wordpress theme, I have the following element powering a countdown.

    <figure class="mike"
             data-show-start-time="<?php echo $start_time; ?>"
             data-show-end-time="<?php echo $end_time; ?>"
             data-show-current-time="<?php echo time(); ?>">...</figure>

    $start_time and $end_time are retrieved as timestamps using get_field(), and presumably everything is in the same timezone since all timestamps are computed server side.

    My problem is that the current time is always way ahead of the end time. I looked in the ACF DateTime picker code and saw its use of PHP’s strtotime, and I wondered if some relative date calculation is throwing something off, but I found the timestamps matched the fields exactly.

    I never change timezones at any point in my code, but I can literally put a start time in the past and an end time in the future and still end up with the countdown reporting that it was long finished.

    Here’s an empirical example.

    <figure class="mike" data-show-start-time="1407008220" data-show-end-time="1407009540" data-show-current-time="1407024748">

    Just to aid my understanding, how does ACF’s date picker behave differently than my use of time()? I’d like to understand why time() seems to give me dramatically different results even though I’m to understand everything is timezone independent.

  • Ah, as is normally the case, the answer is that I am an idiot.

    When I was setting times in ACF’s time picker, I was setting times in the past and future relative to my clock, which is way behind UTC. Wish I caught that before I posted!

    Sorry to waste your time, and thanks for reading.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Timezone confusion over ACF DateTime picker’ is closed to new replies.