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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top