Convert UTC/GMT time to local time

前端 未结 11 1006
情深已故
情深已故 2020-11-22 04:39

We are developing a C# application for a web-service client. This will run on Windows XP PC\'s.

One of the fields returned by the web service is a DateTime field. Th

11条回答
  •  遥遥无期
    2020-11-22 05:10

    Don't forget if you already have a DateTime object and are not sure if it's UTC or Local, it's easy enough to use the methods on the object directly:

    DateTime convertedDate = DateTime.Parse(date);
    DateTime localDate = convertedDate.ToLocalTime();
    

    How do we adjust for the extra hour?

    Unless specified .net will use the local pc settings. I'd have a read of: http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx

    By the looks the code might look something like:

    DaylightTime daylight = TimeZone.CurrentTimeZone.GetDaylightChanges( year );
    

    And as mentioned above double check what timezone setting your server is on. There are articles on the net for how to safely affect the changes in IIS.

提交回复
热议问题