求一段C#代码 能够修改本机时间

yuanmanguo 2008-01-08 11:45:07
求一段C#代码 能够修改本机时间(即客户端在与服务器连接时如果客户端的时间与服务器时间不一致,则将客户端的时间修改为服务器时间)
...全文
257 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
leehong0704 2008-01-08
  • 打赏
  • 举报
回复
B/S模式还是C/S模式
王集鹄 2008-01-08
  • 打赏
  • 举报
回复
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class 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")]
public static extern void GetSystemTime([In, Out] SystemTime st);

[DllImport("Kernel32.dll")]
public static extern bool SetSystemTime([In, Out] SystemTime st);

SystemTime vSystemTime = new SystemTime();
GetSystemTime(vSystemTime); // 读
vSystemTime.year += 1;
SetSystemTime(vSystemTime); // 写

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧