From 6430a50bdf73c051aa5ea03c038d4e771660288b Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Thu, 9 Jun 2022 09:21:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AEWindows?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=97=B6=E9=97=B4=E7=9B=B8=E5=85=B3=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi/WindowsSystem/README.md | 1 + .../WindowsSystem/WindowsSystemTime.cs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Falcon.SugarApi/WindowsSystem/README.md create mode 100644 Falcon.SugarApi/WindowsSystem/WindowsSystemTime.cs 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; + } + } +}