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

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');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.