# Default Output Timezone

**URL:** <https://discourse.cakephp.org/t/default-output-timezone/3170>\
**Category:** Need Help\
**Created:** [September 12, 2017, 4:58pm UTC](https://discourse.cakephp.org/t/default-output-timezone/3170 "2017-09-12T16:58:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdeeming](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cdeeming](https://discourse.cakephp.org/u/cdeeming)\
**Post date:** [September 12, 2017, 4:58pm UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/1 "2017-09-12T16:58:42Z")

</div>

I want to save all date/times in UTC and display for UK time (inc day light savings) so I leave:

date\_default\_timezone\_set(‘UTC’);  
ini\_set(‘intl.default\_locale’, Configure::read(‘App.defaultLocale’));  
‘defaultLocale’ =\> env(‘APP\_DEFAULT\_LOCALE’, ‘en-GB’),

Is there a way to display all the date times with a global timezone and that would not affect them being saved in UTC. Can’t seem to see a setDefaultOutputTimezone() function, though it’s mentioned in the repo a while back.

Would be very handy as I can only see that I have to use the i18nFormat() function for each date that I want to show ajusted…

Please help, driving me bonkers.

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [September 13, 2017, 2:36am UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/2 "2017-09-13T02:36:02Z")

</div>

Set every locale config to UTC and then call [setDefaultLocale](https://api.cakephp.org/3.5/class-Cake.I18n.Time.html#_setDefaultLocale)

I have the following code in my bootstrap.php

```php
// You should change this to UTC
date_default_timezone_set('America/Argentina/Buenos_Aires');

$defaultLocale = Configure::read('App.defaultLocale');
ini_set('intl.default_locale', $defaultLocale);

Cake\I18n\Time::setDefaultLocale($defaultLocale); // For any mutable DateTime
Cake\I18n\FrozenTime::setDefaultLocale($defaultLocale); // For any immutable DateTime
Cake\I18n\Date::setDefaultLocale($defaultLocale); // For any mutable Date
Cake\I18n\FrozenDate::setDefaultLocale($defaultLocale); // For any immutable Date

```

And set defaultLocale (in app) AND timezone(in datasources) in your app.php

---

<div class="post-metadata">

**Author:** ![cdeeming](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cdeeming](https://discourse.cakephp.org/u/cdeeming)\
**Post date:** [September 13, 2017, 9:44am UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/3 "2017-09-13T09:44:09Z")

</div>

Thank you for the reply.

bootstrap.php:

> date\_default\_timezone\_set(‘UTC’);
> 
> $defaultLocale = Configure::read(‘App.defaultLocale’);  
> ini\_set(‘intl.default\_locale’, $defaultLocale);
> 
> Cake\I18n\Time::setDefaultLocale($defaultLocale); // For any mutable  
> DateTime  
> Cake\I18n\FrozenTime::setDefaultLocale($defaultLocale); // For any  
> immutable DateTime  
> Cake\I18n\Date::setDefaultLocale($defaultLocale); // For any mutable Date  
> Cake\I18n\FrozenDate::setDefaultLocale($defaultLocale); // For any  
> immutable Date

If I then debug the following on one of my views:

> debug(\Cake\Core\Configure::read(‘App.defaultLocale’));  
> debug(date\_default\_timezone\_get());  
> debug($note-\>created);  
> echo($note-\>created);

I get:

> \src\Template\Element\case-tab-content.ctp (line 890)  
> ‘en\_GB’  
> \src\Template\Element\case-tab-content.ctp (line 891)  
> ‘UTC’  
> \src\Template\Element\case-tab-content.ctp (line 892)  
> object(Cake\I18n\FrozenTime) {
> 
> ‘time’ =\> ‘2017-09-13T09:34:12+00:00’,  
> ‘timezone’ =\> ‘UTC’,  
> ‘fixedNowTime’ =\> false
> 
> }  
> 13/09/2017, 09:34

The note was created at 10:34 UK time. The output of the date doesn’t seem  
to account for day light savings time. Though I believe that the date has  
been stored correctly in UTC

Can you offer any further advice? You help is very much appreciated.

Thanks

Craig Deeming

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [September 13, 2017, 3:47pm UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/4 "2017-09-13T15:47:13Z")

</div>

Are you getting the $note from a database? (I don’t know the time difference between GB and UTC)

Can you try what returns from nice or i18nFormat?

```php
echo $note->created;
echo $note->created->nice();

```

Also can you try with en-GB instead of en\_GB? (the examples use hypen)

---

<div class="post-metadata">

**Author:** ![cdeeming](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cdeeming](https://discourse.cakephp.org/u/cdeeming)\
**Post date:** [September 13, 2017, 4:14pm UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/5 "2017-09-13T16:14:48Z")

</div>

I am running WAMP on window, if that is of any issue.

Thanks

Craig Deeming

---

<div class="post-metadata">

**Author:** ![cdeeming](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@cdeeming](https://discourse.cakephp.org/u/cdeeming)\
**Post date:** [September 13, 2017, 4:15pm UTC](https://discourse.cakephp.org/t/default-output-timezone/3170/6 "2017-09-13T16:15:47Z")

</div>

Type::build(‘time’)  
-\>useImmutable();  
Type::build(‘date’)  
-\>useImmutable();  
Type::build(‘datetime’)  
-\>useImmutable();

^ These are before the setlocale function. Does that effect anything?

Cake\I18n\Time::setDefaultLocale($defaultLocale);  
Cake\I18n\FrozenTime::setDefaultLocale($defaultLocale);  
Cake\I18n\Date::setDefaultLocale($defaultLocale);  
Cake\I18n\FrozenDate::setDefaultLocale($defaultLocale);

Thanks

Craig Deeming
