Codeigniter:无法获得今天的准确时间


codeigniter: unable to get the accurate time for today's

我必须插入当前日期&时间到我的数据库表中,以便跟踪用户"他们最后一次访问是什么时候"

我现在在印度。在我的windows系统中,显示的是5/13/2013 5:58 Pm但是下面的代码显示的是今天的数据&时间为2013-05-13 13:02:28。为什么时间不准确。

我想让全世界的用户都能准确地计时。

我使用了下面的代码。请帮助我找到这个答案。

   $this->load->database();
   $this->load->helper('date');   
   $datestring = "%Y-%m-%d: %d:%h:%i";
   $time = time(); 
   $today=mdate($datestring, $time);
   echo($today);//showing not accurate time, as i explained it above

如果我的问题不清楚,请在下面评论,我会用不同的方式给你解释。

它给你一个UTC时间,而印度时区是UTC + 5.30。因此,您需要在根索引或配置文件中将您的时区设置为Asia/Calcutta

date_default_timezone_set("Asia/Calcutta");

你还需要改变你的$dateString。

$datestring = "%Y-%m-%d: %H:%i:%s";