I used date("Y-m-d H:i:s");
to get current date time format but the result doesn't match with my Windows system.
Example:
<?php
echo "Current date time: ".date("Y-m-d H:i:s")."<br />";
?>
The sample code displaying result:
Current date time: 2012-05-30 01:58:21
But my Windows system date time is 2012-05-30 09:56:04
I have tried using date_default_timezone_set('Asia/Singapore')
function to get my region datetime and it's work but I want it set default in my php.ini.
For example: (it's work)
<?php
date_default_timezone_set('Asia/Singapore');
echo "Current date time: ".date("Y-m-d H:i:s")."<br />";
?>
I have also tried to set default value in php.ini that is date.timezone = ""
changed to date.timezone = "Asia/Singapore"
but doesn't work.
I use Windows 7 Home Premium 64bit and php-5.3.13-Win32-VC9-x86. Does anyone know how to match between these value?
date_default_timezone_set
will supersede php default timezone setting, without needing to restart anything.
But in your case it did not work. that's weird. Try this as this is my last resort:
<?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());
?>
UPDATES:
Since what you need is a default php timezone and permanent solution without using date_default_timezone_set
, following the few simple steps below:
phpinfo.php
with one line content <?php echo phpinfo(); ?>
Loaded Configuration File
. Example value C:\wamp\bin\apache\Apache2.2\bin\php.ini
Open the above php.ini
file with a notepad. Look for the [Date]
and modify as below:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Singapore
datetime.php
. Or you can also verify directly from phpinfo.php
under a h1 header date
by making sure the default timezone is read as "Asia/Singapore" like below:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With