求一个完整的C# 网络同步本机时间的源代码 最好带注释
求一个完整的C#网络同步本机时间的源代码最好带注释要求:内置几个网络同步时间的地址,可以自己添加同步时间的地址,点击按钮开始同步时间,同步成功的话弹出提示。...
求一个完整的C# 网络同步本机时间的源代码 最好带注释 要求: 内置几个网络同步时间的地址,可以自己添加同步时间的地址,点击按钮开始同步时间,同步成功的话弹出提示。
展开
2013-09-16
展开全部
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace SystemTime
{
public partial class FormLocal : Form
{
#region SetLocalTime
[DllImport("Kernel32.dll")]
private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime); [StructLayout(LayoutKind.Sequential)]
private 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 wMilliseconds;
} private void SetSystemTime(DateTime date)
{
SYSTEMTIME lpTime = new SYSTEMTIME();
lpTime.wYear = Convert.ToUInt16(date.Year);
lpTime.wMonth = Convert.ToUInt16(date.Month);
lpTime.wDayOfWeek = Convert.ToUInt16(date.DayOfWeek);
lpTime.wDay = Convert.ToUInt16(date.Day);
DateTime time = DateTime.Now;
lpTime.wHour = Convert.ToUInt16(time.Hour);
lpTime.wMinute = Convert.ToUInt16(time.Minute);
lpTime.wSecond = Convert.ToUInt16(time.Second);
lpTime.wMilliseconds = Convert.ToUInt16(time.Millisecond);
SetLocalTime(ref lpTime);
}
#endregion
}
}以上变是
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace SystemTime
{
public partial class FormLocal : Form
{
#region SetLocalTime
[DllImport("Kernel32.dll")]
private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime); [StructLayout(LayoutKind.Sequential)]
private 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 wMilliseconds;
} private void SetSystemTime(DateTime date)
{
SYSTEMTIME lpTime = new SYSTEMTIME();
lpTime.wYear = Convert.ToUInt16(date.Year);
lpTime.wMonth = Convert.ToUInt16(date.Month);
lpTime.wDayOfWeek = Convert.ToUInt16(date.DayOfWeek);
lpTime.wDay = Convert.ToUInt16(date.Day);
DateTime time = DateTime.Now;
lpTime.wHour = Convert.ToUInt16(time.Hour);
lpTime.wMinute = Convert.ToUInt16(time.Minute);
lpTime.wSecond = Convert.ToUInt16(time.Second);
lpTime.wMilliseconds = Convert.ToUInt16(time.Millisecond);
SetLocalTime(ref lpTime);
}
#endregion
}
}以上变是
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询