Answers.Body: <p>It is possible to work around the Craft 2 bug, by converting the Craft DateTime object to a native one.</p>
  
  <pre><code>{% set craftDateTime = entry.postDate %}
  {% set nativeDateTime = date(craftDateTime|date('c')) %}
  
  {{ nativeDateTime|date('n/d/Y g:ia', 'America/Los_Angeles') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-12T11:10:21.257Z
Answers.LastActivityDate: 2016-12-12T11:10:21.257Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>This is a known Craft 2 bug in our overridden implementation of PHP's DateTime class and how Twig interacts with it.</p>
  
  <p>It should be fixed before the Craft 3 beta launch because it is on our list to stop overriding that class and rely on PHP's native functionality.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-12T03:44:12.763Z
Answers.LastActivityDate: 2016-12-12T03:44:12.763Z
Answers.UserDisplayName: Brad Bell
Body: <p>In my user profiles, I have a text field where the user's timezone is set, in the standard <code>America/New_York</code> format.</p>
  
  <p>Craft's timezone is set to New York, and the server's timezone is set to UTC.</p>
  
  <p>I'm trying to use the Twig date filter to localize the times using the user profile timezone field, but it doesn't seem to be working.</p>
  
  <p>For example:</p>
  
  <p><code>{{ message.postDate | date('n/d/Y g:ia') }}</code> outputs 12/11/2016 1:00pm</p>
  
  <p>I'm hoping that for a user in the pacific timezone, this time will display as 10:00am. But this is what happens:</p>
  
  <p><code>{{ currentUser.userTimezone }}</code> outputs America/Los_Angeles</p>
  
  <p><code>{{ message.postDate | date('n/d/Y g:ia', currentUser.userTimezone) }}</code> still outputs 12/11/2016 1:00pm</p>
  
  <p>I've also tried just hard-coding a different timezone in, to no avail:</p>
  
  <p><code>{{ message.postDate | date('n/d/Y g:ia', 'America/Los_Angeles') }}</code> still outputs 12/11/2016 1:00pm</p>
  
  <p>Am I doing something wrong? Or is there a different way to do this?</p>
  
Tags: <localization><filter><postdate><timezone>
Title: Using user-selectable timezones to show localized post dates
ThreadText: # Using user-selectable timezones to show localized post dates
  
  (Asked by: username_0 on 2016-12-11)
  
  In my user profiles, I have a text field where the user's timezone is set, in the standard `America/New_York` format.
  
  Craft's timezone is set to New York, and the server's timezone is set to UTC.
  
  I'm trying to use the Twig date filter to localize the times using the user profile timezone field, but it doesn't seem to be working.
  
  For example:
  
  `{{ message.postDate | date('n/d/Y g:ia') }}` outputs 12/11/2016 1:00pm
  
  I'm hoping that for a user in the pacific timezone, this time will display as 10:00am. But this is what happens:
  
  `{{ currentUser.userTimezone }}` outputs America/Los\_Angeles
  
  `{{ message.postDate | date('n/d/Y g:ia', currentUser.userTimezone) }}` still outputs 12/11/2016 1:00pm
  
  I've also tried just hard-coding a different timezone in, to no avail:
  
  `{{ message.postDate | date('n/d/Y g:ia', 'America/Los_Angeles') }}` still outputs 12/11/2016 1:00pm
  
  Am I doing something wrong? Or is there a different way to do this?
  
  **Tags:** localization, filter, postdate, timezone
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-12-12. Score: 4 | Accepted answer
  
  It is possible to work around the Craft 2 bug, by converting the Craft DateTime object to a native one.
  
  ```
  {% set craftDateTime = entry.postDate %}
  {% set nativeDateTime = date(craftDateTime|date('c')) %}
  
  {{ nativeDateTime|date('n/d/Y g:ia', 'America/Los_Angeles') }}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2016-12-12. Score: 2
  
  This is a known Craft 2 bug in our overridden implementation of PHP's DateTime class and how Twig interacts with it.
  
  It should be fixed before the Craft 3 beta launch because it is on our list to stop overriding that class and rely on PHP's native functionality.
  
  
  ---
  
  