Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails issue with timezones & formatting dates
    text
    copied!<p>Hoping that someone can help clear up this very annoying situation I find myself in with Grails &amp; Dates &amp; Timezones as my understanding isn't quite complete.</p> <p>To describe the situation, firstly I am in the UK, the server the app is on is in the US (CST)</p> <p>Users login to my app and I have a field which holds their timezone for the sole purpose of formatting dates reliably appropriate to their location.</p> <p>When the application starts up I enforce a default timezone of UTC, and I also use some Joda Dates elsewhere in the app so I set the Joda DateTimeZone also to UTC. But I only use Joda really for fixed dates that shouldn't ever change when presented.</p> <p>So in Bootstrap I have TimeZone.setDefault(TimeZone.getTimeZone("UTC"))</p> <p>Now to the problem, for certain tables I want to record when a user interacted so have a Date field called 'lastModified' and when the record is updated, I simply set it to a new Date() </p> <p>I'm using ajax calls for presenting the data so rather than show the field directly in a GSP its being preprocessed in the controller, and for formatting I create a formatter with </p> <pre><code>DateTimeZone dtz = DateTimeZone.forID(user.timeZone) def DateTimeFormatter tzAwareLongFormatter = DateTimeFormat.forPattern('MM/dd/yyyy HH:mm').withZone(dtz); </code></pre> <p>I thought this would be perfect, and the dates would be held UTC, then as a user with Europe/London tz I'd see the dates formatted correctly.</p> <p>However the times I get are +7 Hours</p> <p>So its acting like its stored the datetime according to what it would be at Server Location , even though I'm setting the default time in Bootstrap.groovy.</p> <p>Is there anything I should set without having to resort to changing the server time itself?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload