J
J
jekahm2016-02-17 13:36:36
PHP
jekahm, 2016-02-17 13:36:36

Displaying the creation time of a record in the database depending on the user's time zone?

Good day!
Interested in the following question.
There is a table in the database for storing blog posts. It has a field of type datetime , which stores the time the post was created in the following format: 2016-02-12 18:50:51 . By default, the site is set to Europe/Moscow time zone . Also, each user in the profile settings can choose their own time zone.
Is it possible to somehow display a list of posts whose creation time will correspond to the user's time zone?
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2016-02-17
@jekahm

Maybe something like this:

$ts = strtotime('2016-02-12 18:50:51'.' MSK');
$tz = new DateTimeZone('Pacific/Nauru');
$date = new DateTime("@".$ts);
$date->setTimeZone($tz);
echo($date->format('Y-m-d H:m:s'));

I
IceJOKER, 2016-02-17
@IceJOKER

Is it - stackoverflow.com/questions/15625834/how-to-convert... ?

A
Alexander N++, 2016-02-17
@sanchezzzhak

Mysql timestamp saves and stores in UTC, but the output is done from the system settings
By default, the system always goes -> config -> query
I think it will be correct to set the hourly search from the script for php then mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question