I am writing a code for time. I write the following code but want to set my default time zone is Pakistan +5.
<?php
date_default_timezone_set("America/New_York");
echo "The time is " . date("h:i:sa");
?>
How can I do this?
The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts. See PHP's list of supported timezones to find the names of all possible timezones you can use for the date.
Definition and UsageThe date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.
PHP has a function for it using GeoIP. The geoip_time_zone_by_country_and_region() function will return the time zone corresponding to a country and region code combo.
if you had access to php.ini (ver 7.2 ) file, then you can set the timezone for once; by initializing the timezone system variable to Asia/Karachi. i.e. find the line date.timezone = and adding "Asia/Karachi" at the end.
date.timezone = "Asia/Karachi"
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