.net中设置系统时间

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

转自 http://search.csdn.net/Expert/topic/847/847765.xml?temp=.8445551

回复人: acptvb(微软全球技术中心 VB技术支持) (

)

感谢您使用微软产品。

.NET并没有提供可以修改系统时间的名字空间(namespace),您可以通过Win32 API的SetSystemTime API函数来设置系统时间:

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 sysTime =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 sysTime);

}

}

请参考microsoft.public.dotnet.framework新闻组上的帖子:

http://groups.google.com/groups?hl=zh-CN&lr=lang_zh-CN|lang_zh-TW|lang_en&ie=UTF-8&selm=O10nq1XjAHA.2184%40tkmsftngp02

希望能对您有所帮助!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航