Jump to content

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


lynxus

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?

 

Ie:

 

$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?

 

Thanks

Graham

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

<?php	
$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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.