WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I display my current time (19 posts)

  1. wiredkiwis
    Member
    Posted 9 years ago #

    Just wondering if there is a way to display "my" current time (and or date) in the menu.
    I know that I can display the time of posts and replies to posts but thought it would be nice to show the current time where I live.
    Is there a way to fetch the current time (and or date) when the site loads.
    I just want to display something like:
    wiredkiwis time:
    12.00am
    or:
    wiredkiwis time:
    October 21, 2004
    12.00am
    I gather this possible, I've had a look through the plugins and forum but no luck (unless I've missed something).
    ps: I'm no coder so be easy on me :)

  2. jumbo
    Member
    Posted 9 years ago #

    <? echo date("F d, Y h:ia"); ?>
    If you want to fine-tune your date properties:
    http://us2.php.net/date

  3. wiredkiwis
    Member
    Posted 9 years ago #

    Hey thanks for that jumbo
    Simple to see once the your shown the way, eh
    I was almost on the right track
    Have a good one
    You've made my day :)

  4. Anonymous
    Unregistered
    Posted 9 years ago #

    Hey jumbo
    me again.. :)
    So I now have the time displayed (which looks very nice thankyou) but I am hoping to get it to show my local time which is 18 hours ahead of Central US time.
    I guess that the time is being echoed from the server as its US based?
    Is there a way to make it show plus 18 hours where ever it is seen in the world?.
    I have tried what I thought would work but me being a newbie isn't helping much!
    thanks in advance

  5. moshu
    Member
    Posted 9 years ago #

    Or, if you are sure about the 18 hrs difference, you can use this one:
    <?php
    $date = date("D M j G:i:s Y", time()+60*60*$diff=18);
    print ($date);
    ?>
    Of course, you can modify the "letters" as you like - see the table on the page that Jumbo linked. Actually I've found this on that page, just by browsing the posts below the table :)
    Oh, and there is something wrong with your date displayed now: wherever you are it cannot be Oct 26...

  6. wiredkiwis
    Member
    Posted 9 years ago #

    Beel, that snipet is working a treak so far. I only have to find 1 hour for daylight savings and I'm right :)
    This is what I have at the moment:
    echo gmdate("M j, g:ia", time() + 43200*($timezone+date("I + 1")));
    But I cannot for the life of me work out where to put the extra "1" .
    I've tried different variations and looked through a bunch of code, uploading is a pain at the moment as there is a problem with the server (a tiny 7k upload times out after a minute and have to try again!)
    moshu: yea I looked through the page that jumbo linked to but don't understand enough about it to know what I'm looking at :)
    Could you check the date again, it says Oct 21 at this end...
    You might have been at the site when I was in the middle of uploading or mucking with digits :)
    I will try your snipet when the server is better can't be bothered with the lack of speed at the moment
    ps: newbie (me) forgot to login with every post :)

  7. moshu
    Member
    Posted 9 years ago #

    I am glad it worked.
    Note. This isn't really the "code" for NZ time - it's working for you since there is an 18 hrs difference between your location and the server's location. If other NZ-ers have their server at home, it won't work for them in this way :)
    But if you use the code that Beel posted AND changing to fit your location - that will be for any NZ-er :)
    <?php
    $timezone = +12;
    echo gmdate("F d, Y H:i:s", time() + 3600*($timezone+date("I")));
    ?>
    you have to put +12 (I guess, LOL) because you are ahead of GMT, while we here in Canada and the US have to use a minus number (being "behind" GMT)

  8. wiredkiwis
    Member
    Posted 9 years ago #

    haha thanks moshu
    I kind realised that I got that wrong.. depending on where the server is in relation to where the user is.. whats that sound homer simpson makes...dooh!... or something? :)
    <?php
    $timezone = +12;
    echo gmdate("F d, Y H:i:s", time() + 3600*($timezone+date("I")));
    ?>

    So this one automatically allows for daylight saving's time and will display my local time, where-ever it's seen from...cool
    Thanks again for the answers too

  9. Damek
    Member
    Posted 8 years ago #

    Another little tip on this topic, if you want to display multiple time zones, and some of them are usually in Daylight Saving when your server's time is not (and vice versa), you can accommodate for it this way:

    <?php
    $timezone = +10;
    echo gmdate("j M Y, g:i a", time() + 3600*($timezone+abs(date("I")-1)));?>

    Use that for the locations that are usually in DST when yours is out of DST (and vice versa). It subtracts 1 from the server's DST offset, and then gets the absolute value (the abs() php function). So, if your server's DST offset is 1, this converts it to 0, and if your server's DST offset is 0, this converts it to -1 and then abs() gets rid of the -.

    It's not perfect; time zones go into DST at different times and they don't all go into DST. But if you're in the northern hemisphere and you want to show your local time alongside a time in the southern hemisphere, using this adjustment for the southern time zone makes the display correct most of the time instead of being an hour off for half the year.

  10. WooPeeee
    Member
    Posted 7 years ago #

    Can I display the local time for a user no matter where they may be? TIA.

  11. WooPeeee
    Member
    Posted 7 years ago #

    bump

  12. WooPeeee
    Member
    Posted 7 years ago #

    bump

  13. Fififi
    Member
    Posted 7 years ago #

    Please be patient - sometimes it takes someone more than just a few hours to think of an answer for you!

  14. Kafkaesqui

    Posted 7 years ago #

    "Can I display the local time for a user no matter where they may be?"

    There's no time/date info for individual users in WordPress. It's likely you'd have to code up something in javascript to accomplish this.

    And as Fififi alludes to, around here patience is more than a virtue.

  15. WooPeeee
    Member
    Posted 7 years ago #

    I don't need your exclamation point, I figured 12 hours would be good!

  16. WooPeeee
    Member
    Posted 7 years ago #

    I'm not talking about users - as in logged in WP writers - I'm talking about readers in different timezones. If it still applies though, thx.

  17. Kafkaesqui

    Posted 7 years ago #

    RE: bumping posts

    The point is, we don't like members bumping posts just because they haven't gotten a timely response.

    http://codex.wordpress.org/Using_the_Support_Forums#Getting_Your_Questions_Answered_on_the_Forum

  18. Kafkaesqui

    Posted 7 years ago #

    "I'm not talking about users "

    The issue is the same, meaning there's nothing in WordPress (or as far as I know, PHP) to provide this.

  19. WooPeeee
    Member
    Posted 7 years ago #

    I just assumed 12 hours was beyond 'timely'. So much for a first impression, no worry, I'm out of here.

    Thx for the final answer though.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.