2016-11-23 120 views
0

这张截图日期时间我的笔记本电脑..日期时间函数PHP

enter image description here

这个截图我的脚本结果

enter image description here

这我的语法

<?php 
session_start(); 
$time = date('Y-m-d, H:i:s'); 
echo $time; 
?> 

为什么不相同.. 请帮我.. 对不起我的英语不好,我是新手

+0

因为您没有设置时区... –

+0

如何设置它? –

+0

你在问时间或格式? –

回答

1

这里是你需要看到的东西....

<?php 
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); 
echo $date->format('Y-m-d H:i:sP') . "\n"; 

$date->setTimezone(new DateTimeZone('Pacific/Chatham')); 
echo $date->format('Y-m-d H:i:sP') . "\n"; 
?> 

http://php.net/manual/de/datetime.settimezone.php

+0

对不起,我不能OOP –

0

PHP 5.1回报的时间SERVER,可以在世界任何地方。

您的计算机显示您的本地时间(或您设置的时区,通常为您当地的时区)。

使用Milos的解决方案告诉PHP你想使用什么时区。但许多人会建议使用时间服务器100%的准确性,因为您的服务器(以及您的计算机)可能本身没有正确设置。

有关timeserver示例,请参阅http://www.kloth.net/software/timesrv1.php

0

请试试这个。

<?php 

$date_time = new DateTime(); 
echo $date_time->format('Y-m-d H:i:s'); 
?>