Welcome, Guest
Username: Password: Remember me

TOPIC: timezone date

timezone date 15 Jun 2016 11:11 #14070

  • albert
  • albert's Avatar
  • Offline
  • Senior Member
  • Posts: 70
  • Thank you received: 2
  • Karma: 2
Hi,
When i save created date and modified date, the time displayed in the database and in the design is the UTC, i 've read that it takes the timezone from the Joomla user or the one by default.
I checked that, and always is stored and displayed the utc independently of the timezon configured.
How could i solve?

tahnks,
Albert
The administrator has disabled public write access.

timezone date 15 Jun 2016 13:48 #14071

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Are you sure of that.

Did you configured correctly the timezone in the user's configuration profile ?

Do you display the date with JDom?
Can you tell us wich project / Table / Layout ? (PTL)
I will have a look, but I think all this is working because I have been working on that recently.
Coding is now a piece of cake
The administrator has disabled public write access.

timezone date 15 Jun 2016 14:05 #14072

  • albert
  • albert's Avatar
  • Offline
  • Senior Member
  • Posts: 70
  • Thank you received: 2
  • Karma: 2
Yes, It is configured correctly.

I do not display the date with dom, i simply take the data from the database and i display.
But i want to store the data +2h in the database, and i do not know where to do?
maybe i should do in the model on the function save?
The administrator has disabled public write access.

timezone date 15 Jun 2016 14:11 #14073

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
So, that's the reason why.

No, don't touch the model, don't touch the database.
The date MUST ALWAYS be stored in UTC. Obligation, no way out.

If you store different offsets, then a user could change its user parameters and then your system would be unstable of in some case could affect the security.
NEVER do that.

You need to set the offset every time that you want to display the date.

with a JDate object, you can do :
$date->modify('+2hours');

But the best is to apply the user's offset.
You can check JDom : html.fly.datetime
$user = JFactory::getUser();
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));

EDIT : Sorry, I reviewed the code. Now it is better.
Coding is now a piece of cake
Last Edit: 15 Jun 2016 14:13 by admin. Reason: Fixed answer.
The administrator has disabled public write access.
Time to create page: 0.063 seconds

Get Started