<p>You can set the site's timezone in Craft, but you won't get different timezones for your locales with that (locales != timezones btw.). But what you can do is to use Twig's <code>|date</code> filter which allows you to specify a different timezone for the output (<a href="https://php.net/manual/en/timezones.php" rel="nofollow">list of supported timezones</a>). If you create your own <code>DateTime</code> object by joining strings, you have to add a timezone here to give the filter a basis for its calculations. Make this match your Craft settings.</p>

<p>The following example works without the Localization package. </p>

<pre><code>{# Set locale time to GMT+2 #}
{% set localeTime = "0:00 +0200" %}

&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Local Time&lt;/th&gt;&lt;th&gt;Sao Paulo&lt;/th&gt;&lt;th&gt;Manaus&lt;/th&gt;
    &lt;/tr&gt;

    {% for hour in 0..23 %}
        {% for min in [0, 15, 30, 45] %}

            &lt;tr&gt;
                {# Join time segments in a format supported by strtotime #}
                {% set timeStep = ['+ ', hour, ' hours ', min, ' minutes']|join() %}

                {# Modify the locale time and output in chosen timezone #}
                &lt;td&gt;{{ localeTime|date_modify(timeStep)|date('H:i') }}&lt;/td&gt;
                &lt;td&gt;{{ localeTime|date_modify(timeStep)|date('H:i', "America/Sao_Paulo") }}&lt;/td&gt;
                &lt;td&gt;{{ localeTime|date_modify(timeStep)|date('H:i', "America/Manaus") }}&lt;/td&gt;
            &lt;/tr&gt;

        {% endfor %}
    {% endfor %}
&lt;/table&gt;
</code></pre>

<p>To bring the site's currently requested locale into the game, just do some comparisons on <code>craft.locale</code>.</p>

<pre><code>{{ craft.locale == 'de-DE' ? localeTime|date('H:i') }}
{{ craft.locale == 'pt-BR' ? localeTime|date('H:i', "America/Sao_Paulo") }}
</code></pre>

CC BY-SA 3.0
2014-06-18T12:20:24.880Z
2014-06-18T13:51:32.733Z
2014-06-18T13:51:32.733Z
carlcs
<p>Is there a way to loop through a day in 15-minute intervals, with the output of said intervals being localizable? This (cringe-worthy) snippet should help explain what I'm trying to accomplish:</p>

<pre><code>&lt;ul&gt;
    {% for hour in 0..23 %}
        {% for min in [0, 15, 30, 45] %}

            {% set foo = [hour, min]|join(':')|date('H:i')|date_modify('+0 days') %}
            &lt;li&gt;{{ foo.localeTime() }}&lt;/li&gt;

        {% endfor %}
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>For me, that snippet results in the unusual error <code>Method "localeTime" for object "DateTime" does not exist</code>.</p>

<p>(This question was asked on g+ by Chris Davis. I copied it to SE, as I didn't want to answer it there!)</p>

<datetime><filter><timezone>
Output DateTime in that timezone related to the current locale?
# Output DateTime in that timezone related to the current locale?

(Asked by: username_0 on 2014-06-18)

Is there a way to loop through a day in 15-minute intervals, with the output of said intervals being localizable? This (cringe-worthy) snippet should help explain what I'm trying to accomplish:

    {% for hour in 0..23 %}
        {% for min in [0, 15, 30, 45] %}

            {% set foo = [hour, min]|join(':')|date('H:i')|date_modify('+0 days') %}
            {{ foo.localeTime() }}

        {% endfor %}
    {% endfor %}


For me, that snippet results in the unusual error Method "localeTime" for object "DateTime" does not exist.
(This question was asked on g+ by Chris Davis. I copied it to SE, as I didn't want to answer it there!)

**Tags:** datetime, filter, timezone

---

## 1 answers

### Answer by username_0 on 2014-06-18. Score: 3 | Accepted answer

You can set the site's timezone in Craft, but you won't get different timezones for your locales with that (locales != timezones btw.). But what you can do is to use Twig's |date filter which allows you to specify a different timezone for the output (list of supported timezones). If you create your own DateTime object by joining strings, you have to add a timezone here to give the filter a basis for its calculations. Make this match your Craft settings.
The following example works without the Localization package. 
{# Set locale time to GMT+2 #}
{% set localeTime = "0:00 +0200" %}


    
        Local TimeSao PauloManaus
    

    {% for hour in 0..23 %}
        {% for min in [0, 15, 30, 45] %}

            
                {# Join time segments in a format supported by strtotime #}
                {% set timeStep = ['+ ', hour, ' hours ', min, ' minutes']|join() %}

                {# Modify the locale time and output in chosen timezone #}
                {{ localeTime|date_modify(timeStep)|date('H:i') }}
                {{ localeTime|date_modify(timeStep)|date('H:i', "America/Sao_Paulo") }}
                {{ localeTime|date_modify(timeStep)|date('H:i', "America/Manaus") }}
            

        {% endfor %}
    {% endfor %}


To bring the site's currently requested locale into the game, just do some comparisons on craft.locale.
{{ craft.locale == 'de-DE' ? localeTime|date('H:i') }}
{{ craft.locale == 'pt-BR' ? localeTime|date('H:i', "America/Sao_Paulo") }}


---

