Setting system time in .NET.

xiaoxiao2021-03-06  90

Transfer from http://search.9cbs.net/expert/topic/847/847765.xml?temp=.8445551

Reply to: ACPTVB (Microsoft Global Technology Center VB Technical Support) ()

Thank you for using Microsoft products.

.NET does not provide the namespace that can modify the system time, you can set the system time via the Win32 API's setSystemTime API function:

Using system; using system.runtime.interopservices;

[StructLayout (LayoutKind.Sequential)] public struct SystemTime {public ushort wYear; public ushort wMonth; public ushort wDayOfWeek; public ushort wDay; public ushort wHour; public ushort wMinute; public ushort wSecond; public ushort wMiliseconds;}

public class Win32 {[DllImport ( "Kernel32.dll")] public static extern bool SetSystemTime (ref SystemTime sysTime); [DllImport ( "Kernel32.dll")] public static extern void GetSystemTime (ref SystemTime sysTime);}

Public class testpinvoke {public static void main () {systemtime systemtime = 3d new systemtime ();

sysTime.wYear = 2002; sysTime.wMonth = 1; sysTime.wDay = 1; sysTime.wDayOfWeek = 1; sysTime.wHour = 1; sysTime.wMinute = 1; sysTime.wSecond = 1; sysTime.wMiliseconds = 1; Win32. SetSystemTime (Ref SystemTime);}

Please refer to the post on Microsoft.Public.dotNet.framework News: http://groups.google.com/groups? HL = zh-cn & lr = lang_en-cn | lang_zh-tw | lang_en & = utf-8 & selm = O10NQ1XJAHA.2184 % 40tkmsftngp02

I hope to help you!

转载请注明原文地址:https://www.9cbs.com/read-122386.html

New Post(0)