PHP convert timezones

Hi Guys,

Just a quick tip here.

There are times when you would like to convert a Timezone (say America/New_York) to another Timezone (say UTC)

With classes such as DateTime and DateTimeZone available from php 5.2+ this task has become piece of cake.

Let me show you how its done.

In our example we will be converting

America/New_York to UTC time

Good thing is that Day light savings are taken into consideration automatically.

Code snippet

This is it you can create a function for the above code in your Util class as shown below and get some conversions happening.

 Generic Function

Usage

 

Just in case you would like to add to above solution please leave you comments.

 

I hope this helps

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.