Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would say that the methodology being used here is fundamentally flawed and that you need to take a different approach.</p> <pre><code>new DateTime(DateTime.Now.Year, // Server date DateTime.Now.Month, DateTime.Now.Day, model.Hours, // Local time model.Minutes, model.Seconds) </code></pre> <p>I can't see a way of 'normalising' the input in this way, unless you have a way of reliably knowing exactly which timezone a user is in. Simply, there's no easy way to turn a date built in this way into UTC.</p> <p>My first question to you is, how is the model being passed from client to server? If you're using javascript/ajax then the solution should be fairly straightforward to solve by constructing the datetime object on the client (which will include their timezone data) and then rely on the browser to convert it to UTC for transit.</p> <p>If you are using Razor\MVC then you can achieve a similar thing with forms encoding, except that you will need to call ToUTC on the server as the browser won't automatically fix the date for you for this media format.</p> <p>Both methods require that you build a full datetime object on the client and then submit it, rather than trying to build it from seconds, minutes, hours on the server. You don't need to expose all this to the client of course, as long as the datetime is fully formed at the point of submission.</p> <p>Once you've got a nice UTC datetime, you can extract just the time if you don't need the rest of it.</p> <p>Hope this helps.</p> <p>Pete</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