Daylight Time Zone conversion in C# asp.net
How to check whether a particular time zone falls under "DAYLIGHTTIMEZONE" or not using C# asp.net?
If the time zone falls under "DAYLIGHTTIMEZONE" should i be changing the time into standard time zone?
I will get the time zone(Time Zones Listed in Windows OS) as input from user and store it in database,whenever the user logs in i will display the time and date based on the timezone selected by the user.No开发者_JAVA技巧w what role does daylightsaving play here? Whether any changes should be made if the particular timezone falls under "DaylightsavingZone".
Use the TimeZoneInfo
class introduced in .NET 3.5.
It's not clear what your bigger goal is, but basically TimeZoneInfo
should cover whatever you're trying to do, such as converting from one time zone to another. It's not always the simplest class to use correctly, partly because the DateTime
type is badly designed to start with, unfortunately :(
I'm working (occasionally!) on a new date and time library for .NET called Noda Time, but unfortunately that's not ready yet :(
EDIT: Okay, so your steps should be:
- Work out how to get the time zone from the user in an appropriate form for
TimeZoneInfo
. You'll want to end up storing theId
in the database. - When you want to display a time:
- Fetch the time zone using
FindSystemTimeZoneById
- Get the current time using
DateTimeOffset.UtcNow
- Call
TimeZoneInfo.ConvertTime
to convert to the target time zone - Format the result appropriately for the user
- Fetch the time zone using
I think you are looking for TimeZone.IsDaylightSavingTime
精彩评论