看这个对你又没有用~~
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace 系统时间
{
省略。。。。。。。。。。。。。。。
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
[DllImport("Kernel32.dll")]
public static extern void GetLocalTime(SystemTime st);
[DllImport("Kernel32.dll")]
public static extern void SetLocalTime(SystemTime st);
[StructLayout(LayoutKind.Sequential)]
public class SystemTime
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMillsecond;
}
private void button1_Click(object sender, System.EventArgs e)
{
SystemTime st =new SystemTime();
st.wYear=(ushort)this.dateTimePicker1.Value.Year;
st.wMonth=(ushort)this.dateTimePicker1.Value.Month;
st.wDay=(ushort)this.dateTimePicker1.Value.Day;
st.wHour=(ushort)this.dateTimePicker1.Value.Hour;
st.wMinute=(ushort)this.dateTimePicker1.Value.Minute;
st.wSecond=(ushort)this.dateTimePicker1.Value.Second;
SetLocalTime(st);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
SystemTime st =new SystemTime();
GetLocalTime(st);
label1.Text=Convert.ToString(DateTime.Now.TimeOfDay);
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.dateTimePicker1.Value=DateTime.Now;
}
}
}