diff --git a/Falcon.SugarApi/WindowsSystem/README.md b/Falcon.SugarApi/WindowsSystem/README.md new file mode 100644 index 0000000..10cf320 --- /dev/null +++ b/Falcon.SugarApi/WindowsSystem/README.md @@ -0,0 +1 @@ +封装一些Windows操作系统相关操作 \ No newline at end of file diff --git a/Falcon.SugarApi/WindowsSystem/WindowsSystemTime.cs b/Falcon.SugarApi/WindowsSystem/WindowsSystemTime.cs new file mode 100644 index 0000000..51bb7f6 --- /dev/null +++ b/Falcon.SugarApi/WindowsSystem/WindowsSystemTime.cs @@ -0,0 +1,46 @@ +锘縰sing System; +using System.Runtime.InteropServices; + +namespace Falcon.SugarApi.WindowsSystem +{ + /// + /// Windows绯荤粺鏃堕棿 + /// + public static class WindowsSystemTime + { + [StructLayout(LayoutKind.Sequential)] + private struct Systemtime + { + public short year; + public short month; + public short dayOfWeek; + public short day; + public short hour; + public short minute; + public short second; + public short milliseconds; + } + + [DllImport("kernel32.dll")] + private static extern bool SetLocalTime(ref Systemtime time); + + /// + /// 璁剧疆Windows绯荤粺鏃堕棿銆傚簲鐢ㄧ▼搴忓繀椤讳互绠$悊鍛樿韩浠借繍琛岋紝鍚﹀垯鏃犳硶璁剧疆 + /// + /// 闇瑕佽缃殑鏃堕棿 + /// 杩斿洖绯荤粺鏃堕棿璁剧疆鐘舵侊紝true涓烘垚鍔燂紝false涓哄け璐 + public static bool SetLocalDateTime(DateTime dt) { + Systemtime st; + st.year = (short)dt.Year; + st.month = (short)dt.Month; + st.dayOfWeek = (short)dt.DayOfWeek; + st.day = (short)dt.Day; + st.hour = (short)dt.Hour; + st.minute = (short)dt.Minute; + st.second = (short)dt.Second; + st.milliseconds = (short)dt.Millisecond; + bool rt = SetLocalTime(ref st); + return rt; + } + } +}