How to Set Timezone using PHP

Set Timezone using PHP
Set Timezone using PHP

DateTimeZone is the representation of time zone. You can change the timezone using this function.

For example, If you want Indian time zone, use “Asia/Kolkata”.

$dtz = new DateTimeZone("Asia/Kolkata"); //Your timezone
$now = new DateTime(date("Y-m-d"), $dtz);
echo $now->format("Y-m-d H:i:s");

This link will give you a list of time zones.

Use this function date_default_timezone_get() to know the default timezone of your server.

$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;

OUTPUT: The current server timezone is: Europe/Paris

2 Responses

  1. Hola! I’ve been reading your blog for a long time now and finally got the courage to go ahead and give you a shout out from Huffman Tx!
    Just wanted to tell you keep up the great work!

Leave a Reply to Karthick Sugumar Cancel reply

Your email address will not be published. Required fields are marked *