Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set time zone in PHP for Pakistan

Tags:

timezone

php

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?

like image 549
Guria Shonu Avatar asked May 17 '16 11:05

Guria Shonu


People also ask

What timezone is UTC for PHP?

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.

What is timezone PHP?

Definition and UsageThe date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

How can I get time zone and country code in PHP?

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.


1 Answers

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"
like image 145
Adeel Raza Azeemi Avatar answered Oct 21 '22 07:10

Adeel Raza Azeemi