0

So we have in-house servers here in this EDT part of the USA America/New_York and for someone reason, this [SSCCE][1] code is not working.

<?php echo date_default_timezone_get() . " <br />"; $dateCal = "2015-06-22 13:00:00"; // EDT Time $schedule_date = new DateTime($dateCal, new DateTimeZone("America/Chicago") ); echo $dateCal . " <br />"; // 2015-06-22 13:00:00 echo date_format($schedule_date, 'Y-m-d H:i:s T'); // 2015-06-22 13:00:00 CDT ?> 

The output results in:

UTC 2015-06-22 13:00:00 2015-06-22 13:00:00 CDT 

When the 2nd time should be 12 NOON, instead of 1PM.

How do I fix this?

4
  • 1
    Why should it be noon? You never change the timezone. Commented Jun 23, 2015 at 14:32
  • So how would you propose I make the date in accordance with that user profile's timezone? (They have theirs to America/Chicago while we are in America/New_York) Commented Jun 23, 2015 at 14:33
  • 2
    Correct me if I'm wrong - but all that code is doing is creating a new DateTime object with an "America/Chicago" timezone and spaffing it out again... you're not actually doing anything with it? Commented Jun 23, 2015 at 14:34
  • I am an idiot. I just realized my error. Commented Jun 23, 2015 at 14:36

1 Answer 1

4

You're not quite handling timezones correctly

// set the datetime in the EDT timezone $schedule_date = new DateTime("2015-06-22 13:00:00", new DateTimeZone("America/New_York") ); echo $schedule_date->format('Y-m-d H:i:s T'). " <br />"; // 2015-06-22 13:00:00 // change it to CDT $schedule_date->setTimeZone(new DateTimeZone('America/Chicago')); echo $schedule_date->format('Y-m-d H:i:s T'). " <br />"; // 2015-06-22 12:00:00 

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Of course. Set first then echo. But setting it by creating a new timezone and then applying it. I see where I went wrong. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.