• shrapnel

    (@shrapnel)


    Hi all,

    I want to display all my posts using UTC time. So I changed the relevant option to a variation of ′0′ from GMT, and reformatted the get_time php format string in my theme to list the ′T′ field for time zone.

    The time displayed is correct — it actually *is* UTC time. But for some reason it displays ′MST′ instead.

    My hosting provider uses php 4.4.4.

    Ideas?

    Thanks,

    S

Viewing 3 replies - 1 through 3 (of 3 total)
  • Shrapnel, have you gotten this to work, by any chance?

    I have a similar problem. I want to show the WordPress time zone next to my post’s time stamps. If I use ANY of the PHP time-zone abbreviations (e, I, O, P, T, or Z), they reflect the SERVER’s local time zone. Changing the offset in the WordPress control panel does nothing.

    I have also discovered that the time/date shown for each post corresponds to the post_date for the item, not the post_date_gmt.

    For most users, this is a good thing. If they posted at 6 pm their local time, they want to see “6:00 pm” next to their post. If they move three time zones away and reset their WordPress time-zone settings, they do not want to see the post time change to “3:00 pm” for that same post. None of them use the time-zone display settings, so they are unaware of the underlying incorrect date/time.

    I travel all over the world, though, and I LIKE the idea of having my post times change depending on how I set the offset in WordPress. I really do want my post date/time to be based on the GMT value (post_date_gmt), not the local post_date.

    I can make out a little bit of what is going on in the_date functions in general-template.php. I can see that there is a $gmt option for get_post_time, but I do not see any way of passing it through from the_date or the_time.

    Is there any way to get the real, GMT date/time for a post, so I can display it in my custom theme? What would I replace the normal “the_date” or “the_time” calls with to make it work? I have looked, and do not see a hack or a combination of functions to make it work. I suspect that I could create my own function based on the_date, the_time, get_the_time, and so on, but I am not 100% sure how.

    I also help this post sheds some light on the problem that shrapnel faced. When WordPress builds the date/time it is not really building a correct GMT/UTC based date/time. It is taking the post_date, which was adjusted correctly to account for the local time of the person posting it, then sticking it into the server’s local time zone. If you use one of the PHP date/time flags that show the time zone, then you see the problem right away.

    Any ideas?

    For world-travelers looking for a workaround, you can try what I did. I set the offset in WordPress to zero, so the post_time would ALWAYS be in GMT/UTC time. I then removed the display of the time zone, because it is always wrong. If I wanted to, I could add the string “UTC” to my theme, after the time display, but I have not bothered. I am hoping for a more elegant solution soon.

    Also, if anyone thinks that WordPress handles time poorly, take a look at the code searching for ‘gmt_offset’. WordPress generally does a really elegant job handling local and UTC times. Almost everywhere the time is adjusted properly. These display functions are rare exceptions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘UTC appears as MST using php ‘T’ time format’ is closed to new replies.