PHP getting local date and time

Jinu Joseph Daniel picture Jinu Joseph Daniel · Jul 22, 2012 · Viewed 9.1k times · Source

How to get the local date and time in PHP.For example my timezone is Asia/Kolkata. My application has to add the date in my time zone to the database.I know the time can be found by adding 5.30 hrs to UTC time.But what about the date.After some googling I found that there is a DateTime object and it has a function setTimezone() to set the time zone.But after setting how can i get the current date in my time zone.?

Answer

FatalError picture FatalError · Jul 22, 2012

You should rather use "date_default_timezone_set()" functions, once it is set, all the date time function will treat it as local timezone. I believe, you can also set it using php.ini

http://pk1.php.net/manual/en/function.date-default-timezone-set.php