I am trying to create a small method that converts time from one time zone to another. I thought it would be simple enough, but when I breed it, I get this error. The UTC Offset of the local dateTime parameter does not match the offset argument. I assume this is because the server is not in the same time zone as the user who is not helping, as this will be used from all over the world.
public object ConvertDate(DateTime inputTime, string fromOffset, string toZone) { var fromTimeOffset = new TimeSpan(0, - int.Parse(fromOffset), 0); var to = TimeZoneInfo.FindSystemTimeZoneById(toZone); var offset = new DateTimeOffset(inputTime, fromTimeOffset); var destination = TimeZoneInfo.ConvertTime(offset, to); return destination.DateTime; }
Where fromOffset is a number converted to a time interval from the user's time zone, and toZone is the name of the zone into which we are converting. The error on this line is var offset = new DateTimeOffset(inputTime, fromTimeOffset);
Any ideas on how to do this?
c # datetime
Toxicable
source share