1

I have figured out how to get the time using date('g:i a', time()) to output on the chat i'm making. It outputs something like 7:54 pm. The promlem is that I am in the Central Timezone and it is 8:54 my time. I tried using date('g' + 1 + ':i a', time()) but that didn't work. Any Ideas?

Thanks

B. Camp
  • 29
  • 9
  • Could [this question](http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) be of use? Are you using any time-handling libraries, like [moment.js](http://momentjs.com/)? – Timmah Nov 17 '15 at 03:15
  • 1
    Possible duplicate of [Setting timezone to UTC (0) in PHP](http://stackoverflow.com/questions/7587435/setting-timezone-to-utc-0-in-php) – acupofjose Nov 17 '15 at 03:20
  • no, I'm just using pure js. I thought it was easier to convert to different timezones. – B. Camp Nov 17 '15 at 03:20
  • Your code is PHP, not JavaScript – John Conde Nov 17 '15 at 03:21
  • no duh. I was talking about the first comment. Thankyou for solving my problem! – B. Camp Nov 17 '15 at 03:33

1 Answers1

2

Use DateTime() with DateTimeZone():

$date = new DateTime(null, new DateTimeZone(date_default_timezone_get()));
$date->setTimeZone(new DateTimeZone('America/Chicago'));
echo $date->format('g:i a');

I use date_default_timezone_get() to get the current time zone and then change it using DateTime::setTimeZone()

John Conde
  • 217,595
  • 99
  • 455
  • 496