Jump to content

Change a Date to a Different date based on timezone..


Recommended Posts

Hi Guys..


How can I change a date on the fly ?

Everything is UTC on my server.


How can I change a date to something else on the fly?




$timezone = "cet";

$datetime = "2011-09-04 19:53:00";


echo $datetime($timezone);


So I can give it a datetime and have it echo the datetime as if it were in the other timezone?




Link to comment
Share on other sites

I did think of " date_default_timezone_set('America/Los_Angeles');"


However, Does this now change the timezone of the script?

I dont want this.


i want the script to stay in UTC however I want to be able to echo a date through a function that turns the inputted date into whateever datetime i ask for ?


( im not sure how strtotime will fix this issue? Can I punt a timezone to it?

Link to comment
Share on other sites

None currently ( Im assuming the data is correct in the DB )


I get dates from the database ( thats saved as UTC )


Id like to convert some dates on the fly to other timezones ( so i can display datetimes in other peoples locales ) 


I hope that makes sense?


Link to comment
Share on other sites

$myDateTime = new DateTime('2011-09-04 23:05', new DateTimeZone('GMT'));
$myDateTime->setTimezone(new DateTimeZone('America/New_York'));
echo $myDateTime->format('Y-m-d H:i');

Combination of the ‘select’ and ‘function’ will enable you to select ‘time zone’. Then you can manipulate the above code.

Link to comment
Share on other sites

  • 3 months later...


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.