WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Have live date and time updated in sidebar (3 posts)

  1. wilsontd
    Member
    Posted 4 years ago #

    Hello, I would like to be able to display at the top of a sidebar (in a text widget) a simple, single line that shows the live date and time.

    Wed 01-27 | 10:13 am

    I found some code, and managed to alter it and place it into my theme's functions.php file without causing the theme to crash, I think. (Atahualpa theme)

    I don't know whether the function should respond with "echo" or "return"

    --- begin code snippet -----
    function tim_time {
    date_default_timezone_set('EST');
    $tt = date('D m-d | h:i a');
    echo $tt
    }

    OR

    function tim_time {
    date_default_timezone_set('EST');
    $tt = date('D m-d | h:i a');
    return $tt
    }
    --- end code snippet -----

    But I have not figured out what syntax to put into the text widget to call this function.

    Also, I have no idea if it would show a live, running time-- or just a 'snapshot' of whatever time it was when the function was "first" run.

    Can any kind soul take mercy on me and point me down the right path??

    THANK YOU!

  2. alkafy
    Member
    Posted 4 years ago #

    PHP won't be able to give you a "live" clock; only a snapshot, as you mentioned. Look into Javascript clocks, like this tutorial: http://www.elated.com/articles/creating-a-javascript-clock/

  3. wilsontd
    Member
    Posted 4 years ago #

    That is exactly what I needed!

    Thank you so much, alkafy!

Topic Closed

This topic has been closed to new replies.

About this Topic