4

I am using the following in a plugin which I would expect to simply output the time of the server.

// get current time
$time = date("g:i a");
// outputs 9:36am

In a straight .php file this is correct - however, from within the plugin the time is an hour out - 8:36am. I imagine this might be to do with British Summer Time. However, in Crafts general settings I have set Timezone to UTC+1 (BST) - Europe/London

William Isted
  • 328
  • 2
  • 14
Taylermade
  • 131
  • 1
  • 5

1 Answers1

4

Yes, Craft calls date_default_timezone_set('UTC'); when initializing, so PHP will output all times in UTC by default.

If you want to output a time using the timezone that Craft has been set to in General Settings, you can do that with a DateTime object.

$now = new DateTime();
$time = $now->format('g:i a');
Brandon Kelly
  • 34,307
  • 2
  • 71
  • 137