how to set timezone in php
snippet in php

how to set timezone in php

user6157

//Use the date_default_timezone_set("your timezone") to set it globally;
$timezone = "Asia/Kolkata"
date_default_timezone_set($timezone);

$date = new DateTime;  //Now creating a new date instance shall give a time
var_dump($date);

//For setting it locally use setTimezone() method on DateTime instance
$date = new DateTime;
$date->setTimezone(new DateTimeZone($timezone));
//setTimezone() takes instance of DateTimeZone as arguments

//or even shorter
$date = new DateTime("now",new DateTimeZone($timezone));

php change timezone

user7331

date_default_timezone_set('America/Los_Angeles');