php time() problem

WBOY
Release: 2016-08-23 09:17:51
Original
1755 people have browsed it

time() obtains the server time, so is the time obtained in China and the United States the same? Because there was a development problem, the product group buying activity has ended in China, but it can still be purchased abroad. All times use timestamps, and the start time of the database is consistent. Is it a problem with time()?

Reply content:

time() obtains the server time, so is the time obtained in China and the United States the same? Because there was a development problem, the product group buying activity has ended in China, but it can still be purchased abroad. All times use timestamps, and the start time of the database is consistent. Is it a problem with time()?

The timestamp is the total number of seconds from 00:00:00 GMT on January 1, 1970 to the present.
So, this value has nothing to do with time zone. What is related to time zone is time. For example, 1471827600 is Beijing time (2016-08-22T09:00, East 8th District), then the same timestamp will be in East 7th District. 2016-08-22T08:00.

The answers above and below are both correct, the timestamp has nothing to do with the time zone. But when the timestamp is converted into date and time format, it is related to the time zone. The previous answer was wrong... I apologize for misleading the questioner.

<code class="php">$time = time();
date_default_timezone_set('America/Los_Angeles'); 
echo time() . PHP_EOL;
echo date('Y-m-d H:i:s', $time) . PHP_EOL;

date_default_timezone_set("UTC"); 
echo time() . PHP_EOL;
echo date('Y-m-d H:i:s', $time) . PHP_EOL;</code>
Copy after login

time() obtains a timestamp, and timestamps have no time zone and are all in Greenwich time. So unless the server times of your two servers are inconsistent, the time() obtained will be consistent.

The time zone is different

The unified time zone is UTC, I have also encountered it

The time() function obtains a timestamp, and there is no concept of time zone.
But if you use two servers at home and abroad, set the same timestamp to start selling, and the same timestamp to end selling, then when the domestic starts, the foreign The website does not have a beginning. (The basis for speculation is that the subject said that it has not ended at home and abroad, and the sales last for the same time.) Because the timestamp is converted into time, there is the concept of time zone, so if you want to sell at the same time and end at the same time, You need to convert the time between the two places into Greenwich Mean Time (the origin of timestamps), then get different timestamps, and just add the sales time you want to last.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!