Why time and date show different time?

Hello! Has anyone been faced with the fact that the date and time output a different time?
Ie I write for example:
$date_now = date("Y-m-d H:i:s");
$time_now = time();
echo "<p>1. $date_now<br>2. $time_now</p>";

The result is a
1. 2013-11-20 12:04:58
2. 1384923898

In the first case, all right, but in the second during the conversion time, for example through the service onlineconversion shows Wed, 20 Nov 2013 05:04:58 GMT.
What could be the catch?
October 3rd 19 at 01:19
4 answers
October 3rd 19 at 01:21
Solution
>Time zone is correctly Asia/Novosibirsk
In this trick.
I understand that date() gives the time to the specified area and time() gives gmt/utc.
and time does not account for this? he is the current server time displays or GMT? - Alann commented on October 3rd 19 at 01:24
just why, then, when I'm in a different place on the same project to the database just write time and write to the database, in the database it correctly? - Alann commented on October 3rd 19 at 01:27
http://php.net/manual/ru/function.time.php - bridget commented on October 3rd 19 at 01:30
Maybe if you record in a field of type datetime, the server causes the time value to the area that installed on it. - bridget commented on October 3rd 19 at 01:33
no, I just write the time, in unix format - Alann commented on October 3rd 19 at 01:36
in manami's nothing, unfortunately, not found. - Alann commented on October 3rd 19 at 01:39
In the manual there is a comment with a verification example:
The documentation should have this info. The function time() returns always timestamp that is timezone independent (=UTC). "; date_default_timezone_set("Europe/Helsinki"); echo "Europe/Helsinki:".time(); echo "
"; ?> Local time as string can be get by strftime() and local timestamp (if ever needed) by mktime().
- rosina.Johnst commented on October 3rd 19 at 01:42
I tried this example gives the same))) UTC:1384929793 Asia/Novosibirsk:1384929793 - Alann commented on October 3rd 19 at 01:45
October 3rd 19 at 01:23
So I tried: date("Y-m-d H:i:s", time()); ? What gives?
displays as well as date - Alann commented on October 3rd 19 at 01:26
got 1. 2013-11-20 12:20:22 2. 1384924822 3. 2013-11-20 12:20:22 1 just - date, 2 time, 3 your format - Alann commented on October 3rd 19 at 01:29
October 3rd 19 at 01:25
ie it turns out both functions it should work? does not account for the UTC time and date into account?
time() basically returns only in utc: >Returns the number of seconds since Unix Epoch (The Unix Epoch, 1 January 1970 00:00:00 GMT) up to the current time. and date() format in accordance with the specified area - Alann commented on October 3rd 19 at 01:28
thank you! clear - Alann commented on October 3rd 19 at 01:31
Not for that :3 - bridget commented on October 3rd 19 at 01:34
October 3rd 19 at 01:27
please tell me more. it turns out if I record in the database with the wrong time, then I sampled and can not do, because it is a field time am I going? It turns out if people will add info to 6:30 in the morning, then in time it will just do the previous day. Do I understand correctly that I need to all time to attribute to +7 hours?
I think it will be easier to write to the database from the formatted value, i.e. here, for example, date(YmdHis, time()), date will be concise view 20131120092343, which just make the selection using strtotime() It will fit if you have at one time shown to all visitors without regard to zones, and generally smacks of a crutch, but still. - Alann commented on October 3rd 19 at 01:30
ahem, not. so it is not necessary)) in principle, he needs to run properly. times and writing and reading work in 7 hours so you will find what you need. looked into different cms, everything you write time, so it is working) thanks - Alann commented on October 3rd 19 at 01:33
indeed, then don't. store the time in utc in the database, i.e. just time() record. it is better to use to store int(11). a field of type timestamp is tied to the timezone of the server, and when migrating to another server can make the shift. in the output format using date(). it is better to specify a forced timezone using http://php.net/manual/en/function.date-default-timezone-set.php otherwise, the time will depend on server installations. - bridget commented on October 3rd 19 at 01:36
Thanks for the detailed answer - bridget commented on October 3rd 19 at 01:39

Find more questions by tags PHP