Convert UTC server time to local client time

I get the FILETIME structure in UTC from the native server (C ++). On the client side of managed (C #), I need to show it as client (!) Local time. Do I need to send server time zone information with FILETIME for this? Or is this information already contained in FILETIME in UTC?

+2
source share
3 answers

Description

You can convert UTC DateTime to local time using TimeZoneInfo

Example

 TimeZoneInfo.ConvertTimeFromUtc(YourDateTime, TimeZoneInfo.Local); 

You can convert UTC DateTime to any time zone if you know the name. For instance.

 TimeZoneInfo.ConvertTimeFromUtc(YourDateTime, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); 

Additional Information

+7
source
 create a class public class TimeConverter { public static DateTime ConvertToLocalTime(DateTime utcTime, string timeZoneId) { if (string.IsNullOrEmpty(timeZoneId)) { return utcTime; } return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcTime, timeZoneId); } } In controller use TimeConverter TimeConverter.ConvertToLocalTime(Date, yourTimeZone)); 
0
source

I don't know what your structure is, but if you can convert it to a standard time string, the DateTime class will parse it. Then just use the ToLocalTime method.

 DateTime time = DateTime.Parse(FILETIME.ToString()); time.ToLocalTime(); 
0
source

All Articles