Please can someone explain how to achieve the following in C#....
Take a double precision decimal value which represents a date and time e.g. 41411.583333, instantiate a DateTime object and then specify the 'Kind' so that the object represents a local time in a certain time zone.
I intend to use the object created from the decimal value as the source time to use in time conversions but I'm confused by how to achieve this.
Surely it is important to specify that the DateTime object represents a local or utc time; otherwise the conversion will be thrown off if the nature of the source time is not fully specified?
Is this achieved by using some property of TimeZoneInfo or DateTime.SpecifyKind or something else? I'm unclear on this.
I want to be sure that the local source time is converted to destination local time ensuring that daylight saving time is observed.
Code so far:
namespace ConvertTime { public interface ConvertTimeClass { double ConvertTime(double inTime, [MarshalAs(UnmanagedType.LPStr)] string sourceTZ, [MarshalAs(UnmanagedType.LPStr)] string destTZ); } public class ManagedClass : ConvertTimeClass { public double ConvertTime(double inTime, [MarshalAs(UnmanagedType.LPStr)] string sourceTZ, [MarshalAs(UnmanagedType.LPStr)] string destTZ) { DateTime sourceDT = DateTime.FromOADate(inTime); TimeZoneInfo sourceTZI = TimeZoneInfo.FindSystemTimeZoneById(sourceTZ); TimeZoneInfo destTZI = TimeZoneInfo.FindSystemTimeZoneById(destTZ); DateTime destDT = TimeZoneInfo.ConvertTime(sourceDT, sourceTZI, destTZI);//convert time double outTime = destDT.ToOADate(); return outTime; } } }Thanks.