0
Welcome Guest! Login
0 items Join Now

Date and Time display

    • Vadique's Avatar
    • Vadique
    • Sr. Rocketeer
    • Posts: 109
    • Thanks: 0

    Date and Time display

    Posted 14 years 6 months ago
    • Hi guys,
      on some templates there is displaying date. It looks like: Wednesday, Aug 18, 2010

      The code responsible for that is:
      <div class="date-block">
      <span class="date1"><?php $now = &JFactory::getDate(); echo $now->toFormat('%A'); ?></span>,
      <span class="date2"><?php $now = &JFactory::getDate(); echo $now->toFormat('%B'); ?></span>
      <span class="date3"><?php $now = &JFactory::getDate(); echo $now->toFormat('%d'); ?></span>,
      <span class="date4"><?php $now = &JFactory::getDate(); echo $now->toFormat('%Y'); ?></span>
      </div>

      can you please advice me how to add time to it?
      I would like to have: Wednesday, Aug 18, 2010, 14:35
    • David Goode's Avatar
    • David Goode
    • Preeminent Rocketeer
    • Posts: 17058
    • Thanks: 890
    • Web Designer and Host

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Hi Vadique,

      Here are all of the variants...

      DAYS
      d - day of the month 2 digits (01-31)
      j - day of the month (1-31)
      D - 3 letter day (Mon - Sun)
      l - full name of day (Monday - Sunday)
      N - 1=Monday, 2=Tuesday, etc (1-7)
      S - suffix for date (st, nd, rd)
      w - 0=Sunday, 1=Monday (0-6)
      z - day of the year (1=365)

      WEEK
      W - week of the year (1-52)

      MONTH
      F - Full name of month (January - December)
      m - 2 digit month number (01-12)
      n - month number (1-12)
      M - 3 letter month (Jan - Dec)
      t - Days in the month (28-31)

      YEAR
      L - leap year (0 no, 1 yes)
      o - ISO-8601 year number (Ex. 1979, 2006)
      Y - four digit year (Ex. 1979, 2006)
      y - two digit year (Ex. 79, 06)

      TIME
      a - am or pm
      A - AM or PM
      B - Swatch Internet time (000 - 999)
      g - 12 hour (1-12)
      G - 24 hour c (0-23)
      h - 2 digit 12 hour (01-12)
      H - 2 digit 24 hour (00-23)
      i - 2 digit minutes (00-59)
      s 0 2 digit seconds (00-59)

      OTHER e - timezone (Ex: GMT, CST)
      I - daylight savings (1=yes, 0=no)
      O - offset GMT (Ex: 0200)
      Z - offset in seconds (-43200 - 43200)
      r - full RFC 2822 formatted date

      So to add time to your existing code you would need to add the following...
      <div class="date-block">
      <span class="date1"><?php $now = &JFactory::getDate(); echo $now->toFormat('%A'); ?></span>,
      <span class="date2"><?php $now = &JFactory::getDate(); echo $now->toFormat('%B'); ?></span>
      <span class="date3"><?php $now = &JFactory::getDate(); echo $now->toFormat('%d'); ?></span>,
      <span class="date4"><?php $now = &JFactory::getDate(); echo $now->toFormat('%Y'); ?></span>,
      <span class="date5"><?php $now = &JFactory::getDate(); echo $now->toFormat('%H:%i'); ?></span>
      </div>
      Then you would need to add suitable CSS for "date5"

      Hope this helps

    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information
    • Vadique's Avatar
    • Vadique
    • Sr. Rocketeer
    • Posts: 109
    • Thanks: 0

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Great. So fast!

      Can you please specify what date Affinity shows when "Client Side Date" is disabled in the template settings?

      (I checked my Joomla settings and my server settings, but template shows some other date, something like 3 hours behind.)
    • Vadique's Avatar
    • Vadique
    • Sr. Rocketeer
    • Posts: 109
    • Thanks: 0

    Re: Date and Time display

    Posted 14 years 6 months ago
    • I added this code line:
      <span class="date5"><?php $now = &JFactory::getDate(); echo $now->toFormat('%H:%i'); ?></span>

      And here's what i get: Saturday, October 16, 2010, 01:%i

      Hour is OK, but minutes doesn't show up.
      %i - looks the right code...
      Any ideas?

      To test it more i added:
      echo date('l jS \of F Y H:i:s');

      And now output is: Saturday, October 16, 2010, 01:%i, Saturday 16th of October 2010 04:38:44

      Strange but those two examples shows different hours 01 and 04...
    • David Goode's Avatar
    • David Goode
    • Preeminent Rocketeer
    • Posts: 17058
    • Thanks: 890
    • Web Designer and Host

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Hi Vadique,

      Interesting - I have various sources and books and they show %i for minutes. However I did notice one marked as %M which I thought was Month.

      Try %H:%M and see if that works.

      My understanding is that if client side is turned off it shows the date and time that the server is set to.

      Hope this helps

    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information
    • Vadique's Avatar
    • Vadique
    • Sr. Rocketeer
    • Posts: 109
    • Thanks: 0

    Re: Date and Time display

    Posted 14 years 6 months ago
    • David Goode wrote:
      Hi Vadique,
      Interesting - I have various sources and books and they show %i for minutes. However I did notice one marked as %M which I thought was Month.
      Try %H:%M and see if that works.
      My understanding is that if client side is turned off it shows the date and time that the server is set to.
      Hope this helps
      Hi David,
      once again thank you for your support.
      %M worked fine.

      But one question remain - the time that is displaying on template.
      I used this code to display time of the template and of the server (but i thought there is no such thing as template time)
      Template time <?php $now = &JFactory::getDate(); echo $now->toFormat('%H:%M'); ?><br>
      Server time<?php echo date('H:i'); ?>
      And here is what i get:
      Template time 11:15
      Server time 14:15

      3 hours difference, why? (Client side time in template settings is disabled)
      Any ideas?
    • Vadique's Avatar
    • Vadique
    • Sr. Rocketeer
    • Posts: 109
    • Thanks: 0

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Hi David,
      any chances to have your advice on this situation?
    • David Goode's Avatar
    • David Goode
    • Preeminent Rocketeer
    • Posts: 17058
    • Thanks: 890
    • Web Designer and Host

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Hi Vadique,

      When you say template time do you mean the local time at which the template is viewed?

      Server time is set by the server operator and for many people their server may be in a different timezone to them. So the difference in time will be due to either incorrect time on server or different time zones.

      This is why there is the option to select 'client side time' as this will display the date and time from the visitor's pc. That way they see the correct date and time for their time zone IF their pc is set correctly.

      Hope this helps

    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information
    • Adamck's Avatar
    • Adamck
    • Elite Rocketeer
    • Posts: 546
    • Thanks: 2
    • Web Developer, IT Assistant, Graphics design, App Developer

    Re: Date and Time display

    Posted 14 years 6 months ago
    • I usually use:
      <?php
      date_default_timezone_set('Europe/Dublin');
      echo date("j M Y: G:ia");
      ?>

      As you can set your default timezone in PHP5 +
      This gives me the UK time as:
      19 Oct 2010: 9:12am

      See www.php.net/manual/en/timezones.php for the different time zones.
    • Kiss my RSS
    • David Goode's Avatar
    • David Goode
    • Preeminent Rocketeer
    • Posts: 17058
    • Thanks: 890
    • Web Designer and Host

    Re: Date and Time display

    Posted 14 years 6 months ago
    • Thanks Adam,

      Great tip 8)

    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information

Time to create page: 0.079 seconds