Support » Fixing WordPress » Getting a correct timestamp to show within the theme.

  • 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:

    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:


    (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:


    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?

  • The topic ‘Getting a correct timestamp to show within the theme.’ is closed to new replies.