datetime in c# for a web application

DateTime.UtcNow is used to get the current UTC time and DateTime.Now is used for the current local time. In the case of a web application, datetime.now will give the server time.

How do I make it give the local time for any user using the application?

Jon Skeet
people
quotationmark

You pass the UTC time back to the client, and let the client do the UTC to local time conversion. Either that, or you need to make the client pass in the time zone, which is a pain in other ways.

Usually it's better to stick to UTC for as much of the time as you can, and only convert into a specific time zone when presenting the data to the user. Note that converting from UTC to local time is lossless; the other way there can be ambiguity due to DST transitions.

people

See more on this question at Stackoverflow