Php datetime does not match my windows system

I used date("Y-m-d H:i:s");to get the current date format, but the result does not match my Windows system.

Example:

<?php
echo "Current date time: ".date("Y-m-d H:i:s")."<br />";
?>

Result of displaying example code:

Current date: 2012-05-30 01:58:21

But my Windows system time is 2012-05-30 09:56:04

I tried using a function date_default_timezone_set('Asia/Singapore')to get my datetime region and it works, but I want it to set a default value in my php.ini.

For example: (it works)

<?php
date_default_timezone_set('Asia/Singapore');
echo "Current date time: ".date("Y-m-d H:i:s")."<br />";
?>

I also tried setting a default value in php.ini, which is date.timezone = ""changed to date.timezone = "Asia/Singapore"but not working.

I am using Windows 7 Home Premium 64bit and php-5.3.13-Win32-VC9-x86. Does anyone know how to combine these values?

+5
3

date_default_timezone_set php , -. . . , :

<?php
header('Content-Type: text/plain');
//date_default_timezone_set('Asia/Singapore');
date_default_timezone_set('Etc/GMT+8');
echo date("Y-m-d H:i:s A T", time());
?>

:

php date_default_timezone_set, :

  • phpinfo.php <?php echo phpinfo(); ?>
  • http://localhost/phpinfo.php Loaded Configuration File. C:\wamp\bin\apache\Apache2.2\bin\php.ini
  • php.ini . [Date] , :

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = Asia/Singapore
    
  • apache. datetime.php. phpinfo.php h1 date, , "/", : enter image description here
+2
  • script - (, Apache) CLI? Apache php.ini.

  • , php.ini? phpinfo() php.ini .

+2

You need to define the default time zone

date_default_timezone_set('Asia/Singapore');

UPDATE

Did you restart the server after changing PHP ini?

+1
source

All Articles