1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Displaying XenForo Date & Time

Discussion in 'XenForo Development Discussions' started by Golden Falcon, Aug 31, 2014.

  1. Golden Falcon

    Golden Falcon Member

    Hello. I'm trying to display the current date and time in a theme.

    What I originally did was just make a PHP file:

      public static function getHtml() {
    $today date("l , F j - g:i a");
    //Sunday , August 31 - 8:09 am
    return $today;
    And then using a <xen:callback> block.

    I realized after that this was bad because it didn't take account the member's different timezones, so I'm going to assume this will just display the server time, which I don't want.

    I see there is this

    <xen:date time="$datetime" />
    But it doesn't work when I try to put it into a header file. I'm trying to wrap the user's current time inside a <span>

    Thank you
  2. AndyB

    AndyB Well-Known Member

    You will need to post this in the template:

    {xen:datetime $var}
    Where $var is a Unix timestamp.
  3. Golden Falcon

    Golden Falcon Member


    Is Unix timestamp the same as PHP - http://php.net/manual/en/function.date.php ?

    Can you declare $var in the same template file? Or can you just replace it with a timestamp?

    {xen:datetime 'l , F j - g:i a'}<
    for example yields "A moment ago..." as the result.
  4. Chris D

    Chris D XenForo Developer Staff Member

    It does need a timestamp as an input. Try this:

    {xen:date $serverTime, 'l, F j - g:i a'}
    LPH likes this.
  5. Golden Falcon

    Golden Falcon Member

    That's perfect. Thanks!

Share This Page