Elxis CMS Forum

Support => General => Topic started by: armpouniotis on January 08, 2014, 15:02:37

Title: About date & time
Post by: armpouniotis on January 08, 2014, 15:02:37
Hi there !

I am using elxis 4.x

Inside the template header I am using:

$eDate = eFactory::getDate();

In body of the template within a <div> I want to display current date & time, and I am using:

<?php $eDate = strftime("%A, %d %b, %Y, | %H:%M"); echo $eDate; ?>

Date is displayed normaly, but unfortunately time is -2 hours...

What should I do to fix it ?


Thank you in advance
Christos
Title: Re: About date & time
Post by: datahell on January 08, 2014, 18:32:59
No, no, no, no, this is absolutely wrong.
$eDate is an instance of the elxisDate library class.

The fastest and easiest method to display the current date is this:

Code: [Select]
$eDate = eFactory::getDate();
echo $eDate->formatDate('now');

To change the date format use one of the 13 built-in multi-lingual date formats:
DATE_FORMAT_1, DATE_FORMAT_2, ..., DATE_FORMAT_13

Example:
$eDate = eFactory::getDate();
$eLang = eFactory::getLang();
echo $eDate->formatDate('now', $eLang->get('DATE_FORMAT_8'));  //example: Saturday Dec 25, 2010

Open the English main language file (language/en/en.php) and look at the top of the file the available formats.

Using strftime is bad as it depends on server default time zone. Elxis is much more advanced than this.
The date is automatically being displayed in your preferable time zone. Even guests can set a preferable time zone (in user's central).
If you haven't picked a time zone then the site's default time zone is used (see Elxis configuration).

elxisDate documentation (https://www.elxis.net/docs/developers/libraries/elxisdate.html) on Elxis Docs.
Title: Re: About date & time
Post by: armpouniotis on January 09, 2014, 16:04:08
Thank you very much for your reply datahell !

that really works !