Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show time with php code with the right timezone

I need to show current time on my site in my city Iran/Tehran

I'm using this code:

 <?php echo date('H:i'); ?> 

but it doesn't show the right time.

my country timezone : iran/tehran

my city time now is : 17:45

but on the site it shows me : 23:15

I don't know what time zone my server is in & I can't change that, please help me.

like image 560
HamidZ Avatar asked Jan 07 '13 14:01

HamidZ


People also ask

How can I get timezone in PHP?

The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.

How do I change the default timezone in PHP?

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

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.


1 Answers

Try to change timezone in you code like that:

date_default_timezone_set('you/timezone');
like image 81
KryDos Avatar answered Oct 16 '22 00:10

KryDos