开发者

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 the Id 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


I think you are looking for TimeZone.IsDaylightSavingTime

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜