Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Jon Skeet may need to correct me, as I'm assuming this is correct in <a href="/questions/tagged/nodatime" class="post-tag" title="show questions tagged 'nodatime'" rel="tag">nodatime</a>:</p> <pre class="lang-cs prettyprint-override"><code>// Timezone data provider (inject with DI) IDateTimeZoneProvider timeZoneProvider = DateTimeZoneProviders.Tzdb; // London Timezone (can keep this as a singleton, since it'll be used often) var londonTimeZone = timeZoneProvider["Europe/London"]; // Get your date/time from the database and map it as being local to London timezone var yourDateFromDb = new DateTime(2013, 01, 23, 21, 00, 00); // This is what you'll get back from your database (although you may get back a DateTimeOffset) ZoneLocalMapping zonedDbDateTime = londonTimeZone.AtLeniently(LocalDateTime.FromDateTime(yourDateFromDb)); &lt;-- This is your date time with the correct offset (taking into account DST etc.) // Map the London zoned date/time to the users local date/time var usersTimezoneId = "Europe/Paris"; // &lt;-- Store this value in users profile/db var usersTimezone = timeZoneProvider[usersTimezoneId]; var usersZonedDateTime = zonedDbDateTime.WithZone(usersTimezone); Assert.That(usersZonedDateTime.Hour == 22); </code></pre> <p>You should probably be aware that during timezone transitions (autumn clock change), you may get 2 possible dates for the zonedDbDateTime. The code here just gets the first or earliest date/time.</p> <p>Edit: Updated code snippet with changes suggested by Jon Skeet</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