Setting time zone in php

Function date_default_timezone_set()>= 5.1.0 set timezone globally.

If you need to set timezone locally, for specific variable, you can use DateTime>= 5.2.0 and DateTimezone>= 5.2.0 classes, like:

$dt = new DateTime('now', new DateTimezone('Asia/Dhaka'));
echo $dt->format('F j, Y, g:i a');

Here is the list of all available timezones in PHP.


Since non of the above functions will work on PHP version 4.x, you have no other way to set timezone, rather that setting your server time to your timezone, or add offset to time() functions, like:

echo date('F j, Y, g:i a', time() - 6*3600); # Bangladesh is in UTC+6

You have to use:

date_default_timezone_set('Asia/Dhaka');

I'm not sure if this is the right timezone.

Tags:

Time

Php