ADVERTISEMENT


Breaking News

Recent Posts

Monday, December 29, 2014

How to convert date timezone with php

. Its very easy way to convert time to required time zone, below is the example to convert time GMT time to los angeles time zone.

- First we are creating php time zone object with our required time zone in this example it "los angeles" which is GMT -8.

- then we creates datetime object with oldtime zone which is GMT by default other wise we can pass it object if any other time zone required.

-setTimeZone is the function which will get the new time zone object and convert date into it, you can echo it and check it out.

1:   $newTimeZone = new DateTimeZone('America/Los_Angeles');  
2:   $date = new DateTime('01-02-2014 09:00:00');  
3:   $date->setTimeZone($newTimeZone);  
4:   echo $date->format('Y-m-d H:i:s')."\n";  

No comments:

Post a Comment

Designed By Published.. Blogger Templates