Reputation: 19515
I want to calculate my countrys((new zealand) local date and time in php but I dont know how to calculate. Please anyone can help me. thanks
Upvotes: 1
Views: 5977
Reputation: 5426
PHP >=5.2.0
$nz_time = new DateTime(null, new DateTimezone('Pacific/Auckland'));
echo $nz_time->format('Y-m-d H:i:s');
PHP 5
date_default_timezone_set('Pacific/Auckland');
echo date('Y-m-d H:i:s');
Upvotes: 4
Reputation: 30563
You have to set default-time-zone and then date function will return you current date and time date_default_timezone_set
Upvotes: 1
Reputation: 67
https://www.php.net/manual/en/function.date.php
If you are using PHP 5.1.0 or later you can also use the timestamp modifier to get the specific time you need.
Otherwise you just need to make the proper calculations to the local time you need against the server time.
Upvotes: 1