CSharp examples for System:DateTimeOffset
Get Utc Offset
// Copyright (c) .NET Foundation. All rights reserved. using System.Windows.Forms; using OpenLiveWriter.Interop.Windows; using System.Runtime.InteropServices; using System.Globalization; using System.Diagnostics; using System;/*from ww w . ja v a2 s .c o m*/ public class Main{ public static TimeSpan GetUtcOffset(DateTime forLocalTime) { DateTime utc = LocalToUtc(forLocalTime); return forLocalTime - utc; } public static DateTime LocalToUtc(DateTime localTime) { System.Runtime.InteropServices.ComTypes.FILETIME localFileTime = ToFileTime(localTime); System.Runtime.InteropServices.ComTypes.FILETIME utcFileTime; Kernel32.LocalFileTimeToFileTime(ref localFileTime, out utcFileTime); return ToDateTime(utcFileTime); } }