• Resolved giangel84

    (@giangel84)


    Hi all,
    I’m trying to display a custom time format with date_i18n function.

    Issue: I have a custom field with unix timestamp format.
    In my template page I get the custom meta field and would display the time in this format: H:i.

    Using
    echo date_i18n('H:i', $timestamp, $gmt);
    It work but it show “15:30” while real time is “16:30”, I think due to local server timezone.

    I tried set $gmt as ‘+0100’ but it doesn’t work. Which is the correct $gmt format to set?
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • A related question is: How would the program know what the user’s timezone is? You could have the user specify timezone when registering, so it would be stored in a database. Alternatively, you can get it via JavaScript.

    Here is a link discussing how to get a user’s timezone in JavaScript:
    stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript

    Thread Starter giangel84

    (@giangel84)

    Timezone is set from web site’s server, not from user’s client.
    Infact by changing local computer timezone, website display always the same time.
    Moreover I don’t need to adjust time related to user’s timezone.

    However I don’t understand how $gmt should working, wordpress documentation is incomplete since there isn’t any example about $gmt format.

    By the way, I managed this problem in this way:
    Requested time format: H:i

    
    <?php //fix hour timezone
    $hour = date_i18n('H', $timestamp) - 2; //fix -02:00 timezone
    $time_to_print = $hour.":".date_i18n('i', $timestamp); //Get format H:i
    ?>
    
    <time datetime="<?php echo date_i18n( 'Y-m-d', $timestamp); ?>T<?php echo $time_to_print; ?>"></time>
    • This reply was modified 7 years, 8 months ago by giangel84.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘GMT format for date_i18n function’ is closed to new replies.