WordPress.org

Ready to get started?Download WordPress

Forums

Getting a correct timestamp to show within the theme. (1 post)

  1. Zegnt
    Member
    Posted 4 years ago #

    This is the first time I’m messing around with the PHP code within a WordPress theme, so please bear with me.

    I am trying to get a timestamp to show up on my posts. Keep in mind that I’m in Sweden which means I have WordPress set to Stockholm as my timezone (UTC+1). Currently I’m going with this code to echo the post timestamp into my theme:

    <?php
    echo str_pad(get_the_time('Y'),5,'0',STR_PAD_LEFT).'-'.get_the_time('m-d\TH:i:sP');
    ?>

    To test this I created a new post. WordPress tells me it has been published at ~15:32. So I would expect to get the following time displayed:

    02010-02-13T15:32:??+01:00

    (The question marks are there because WordPress does save the seconds but doesn’t show them at the publishing page.)

    But this is not the result I’m getting. My theme is giving me this:

    02010-02-13T15:32:20+00:00

    As you can see it gives me a timezone offset of 0. I don’t remember living in UTC time.

    So I went back to my general settings to check on the timezone. There seem to be no problems here, it even proofs to me that I’m not in UTC time by telling me this:

    UTC time is 2010-02-13 14:37:15
    Local time is 2010-02-13 15:37:15

    So, how do I get WordPress to show the right offset?

Topic Closed

This topic has been closed to new replies.

About this Topic