c# - What is the correct way to store and then display DateTimes in .Net? -


i think may have been living in cave time complexities of datetime has sunk in today. i've read few articles recommend storing datetime utc in database , display them local time in view.

however, hit articles said not simple , need consider "instants" , converting user inputted datetime utc hard due timezone id or using touniversaltime() not safe or let javascript post utc datetime , use js display local times if have razor view datetime model property? relying on tolocaltime() cannot considered safe apparently.

i've heard of noda time jon skeet i'm hoping solves although know has commented not perfect.

so in hell people using simple web applications in .net?

is there correct example provide or link posts , renders value timezone sympathetic?

it appears ignorance bliss.

update: example, user has datetimepicker jquery , select datetime of event. users of application global if choose 10am eastern time should appear in view 6pm uk users.

let's take on technologies have: sql server (i consider use sql server, because of ms stack) - datetime type not store time zone offset range, not give other options keep them in utc.

.net gives option manipulate time zones in datetime type. can load values database , change somehow user timezone. , question, how determinate user timezone? ok, if user registered on size - can use settings 'your timezone' , store users (a branch of sites this, sharepoint), each time render view - use setting , render view right timezone. problem can if need use caching - need cache based on user time zones (not best, huh)...

but if have user anonymous , don't have information on him?

let's take on javascript. javascript allows manipulate time zones. can render date related strings on server <date>2013-04-08t12:00:00z</date>, indicates date in utc, after onload can launch js code find date tags on view , transform them browser time zone. (i have article problem developing web application time zones support, has lot of grammar mistakes, sorry that).

so, me - right way keep in utc untill not show user. view should manipulate dates in user time zone (in case should javascript layer), every time need send data dates server - need convert dates utc. each time dates server - convert them first browser time zone , after show user.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -