2

I get from server native (C++) application a FILETIME structure in UTC format. On the managed (C#) client side I need to show it as client(!) local time. Do I need along with FILETIME transfer information about server time zone to accomplish this? Or such information already contains in FILETIME in UTC format?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
user10101
  • 1,704
  • 2
  • 20
  • 49
  • It is not "server UTC time", it is "UTC time". TC is absolute and not machine depenadnt (unless the clock on the machine is simply set wrong). – TomTom Dec 23 '11 at 09:41

3 Answers3

7

Description

You can convert a UTC DateTime to local Time using TimeZoneInfo

Sample

TimeZoneInfo.ConvertTimeFromUtc(YourDateTime, TimeZoneInfo.Local);

You can convert a UTC DateTime to any timezone, if you know the name. For example.

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

More Information

dknaack
  • 60,192
  • 27
  • 155
  • 202
0

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

DateTime time = DateTime.Parse(FILETIME.ToString());
time.ToLocalTime();
Rubarb
  • 85
  • 2
0
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));
Sreenath Plakkat
  • 1,765
  • 5
  • 20
  • 31