How to change UTC time to your local time using PHP

How to change UTC time to your local time using PHP is big question in PHP programming language. Today, PHP Tricks provide you a simple and quick function to covert UTC/GMT time to your local time using  DateTimeZone  PHP class.

 

Suppose you get time in UTC/GMT time format from server and you want to convert it to your Local time So you just copy next function and follow instructions.

You should copy following function where need to pass UTC time (YYYY-mm-dd H:i:s format) and you will get local time in same format.

 

How to call this function ??

Conclusion: Because my local time zone is GMT+5:30 (UTC+5:30) so this functions returns  my exact local time by adding 5 Hours and 30 mins in GMT/UTC time. 

This same function will return different local time according to countries or cities where executed.

Leave a Reply

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