如何获取服务器时间不是php中的本地时间 [英] How to get server time not localtime in php

查看:238
本文介绍了如何获取服务器时间不是php中的本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的第一部分



当我使用 new Date(); 在Javascript中。



它会提供

  2015 11:18:02 GMT + 0530(印度标准时间)



有没有任何函数给服务器时间而不是本地机器时间与 new Date()但是从服务器不是localMachine。



在我的项目中,我使用codeigniter.is有任何方法保持datetime等于servertime不是localmachine时间。 / p>

所以当我使用echo date('Ymd H:i:s')


$ b

回到PHP中的日期,格式与中的 Date()相同:



新日期()列印 Fri Jun 19 2015 11:18:02 GMT + 0530(印度标准时间)



但在Php date('DMYG:i:s T',time()); 2015 11:18:02 IST



如何实现类似 new Date()

解决方案

如果你在真实服务器上工作,我相信你可以通过这个代码段获得适当的时间。

  function server_time()
{
$ this-> load-> helper('date');
echo now();
echo< br>;
}

如果你在本地电脑上使用xampp或wamp,您当地的电脑时间。


First Part of the Question :

When I m using new Date (); in Javascript.

it gives

Fri Jun 19 2015 11:18:02 GMT+0530 (India Standard Time)

This is giving my local machine time.whereas server time is 7 mins ahead.

Is there any function which gives server time not local machine time same exactly as new Date() But from server not localMachine.

In My project i am using codeigniter.is there any method to keep datetime same as servertime not localmachine time.

so when i use echo date('Y-m-d H:i:s'). This gives server time.

Second part of the question :

How to echo date in php in the same format like new Date() in Javascript:

new Date() Prints Fri Jun 19 2015 11:18:02 GMT+0530 (India Standard Time)

But in Php date('D M Y G:i:s T', time()); is giving Fri Jun 19 2015 11:18:02 IST

How to achieve same format like new Date().

解决方案

If you work on real server I believe you can get proper time by this snippet.

function server_time()
{
  $this->load->helper('date');
  echo now();  
  echo "<br>";
}

If you use xampp or wamp on your local pc that time you'll get your local pc time.

这篇关于如何获取服务器时间不是php中的本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆