/* * Copyright (c) 2022 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; namespace AuroraUIComponent.Util { public class SystemTimeUtil { [StructLayout(LayoutKind.Sequential)] public struct SYSTEMTIME { public ushort Year; public ushort Month; public ushort DayOfWeek; public ushort Day; public ushort Hour; public ushort Minute; public ushort Second; public ushort Milliseconds; } [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetSystemTime(ref SYSTEMTIME st); public static int SetUTCTime(DateTime st) { SYSTEMTIME stTime = new SYSTEMTIME(); stTime.Year = (ushort)st.Year; stTime.Month = (ushort)st.Month; stTime.Day = (ushort)st.Day; stTime.Hour = (ushort)st.Hour; stTime.Minute = (ushort)st.Minute; stTime.Second = (ushort)st.Second; stTime.Milliseconds = 0; SetSystemTime(ref stTime); int errorCode = Marshal.GetLastWin32Error(); //throw new System.ComponentModel.Win32Exception(errorCode); return errorCode; } public static int SetLocalTime(DateTime st) { return SetUTCTime(st.ToUniversalTime()); } } }