简体   繁体   English

如何获取当前世界时间

[英]How to get current World Time

The diffrence between 2 dates - current time and mysql time. 2个日期之间的时差-当前时间和mysql时间。 This can be backdoored when user change his PC time and the code is Bypassing him from the diffrence check. 当用户更改他的PC时间并且代码从差异检查中绕过他时,可以将此设置为后门。

I've tried to use 我尝试使用

mktime()

but its not working when my mysql date is 1451094007 (Sat, 26 Dec 2015 01:40:07 GMT) and real world time is for example 1451108407 (Sat, 26 Dec 2015 05:40:07 GMT) 4 hours later, and minimum difference is 10 hours user can still add some hours on him own PC and bypass time. 但当我的mysql日期为1451094007 (星期六,2015年12月26日01:40:07 GMT)并且实际时间为例如1451108407 (星期六,2015年12月26日05:40:07 GMT)时,至少4小时后,区别是10小时用户仍然可以在自己的PC上增加一些时间并绕过时间。

How can I get any world time which can't be manipulated? 我如何获得无法操纵的世界时间?

You get all timezones using in the world store in array then run in loop 您将在数组的世界存储中使用所有时区,然后循环运行

foreach($timezonearray as $timezone){

$time = new DateTime($timezone);
   echo $time->format('Y-m-d H:i:s');
}

it will print result like this http://www.timehubzone.com/worldclock 它将打印如下结果:http://www.timehubzone.com/worldclock

single way 单向

$time = new DateTime('Africa/Abidjan');
   echo $time->format('Y-m-d H:i:s');

you can get all time zones here timezones list 您可以在此处获取所有时区时区列表

You can use other services such as http://worldclockapi.com/ 您可以使用其他服务,例如http://worldclockapi.com/

(see http://worldclockapi.com/api/json/utc/now ) (请参阅http://worldclockapi.com/api/json/utc/now

Fetch the result and feed them to variable. 获取结果并将其输入变量。

Basically, your application should use the server time where it's hosted (configured with server clock) and time() should have respected the server clock 基本上,您的应用程序应该使用托管它的服务器时间(使用服务器时钟配置),并且time()应该尊重服务器时钟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM