110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ChangeDataTime
{
public partial class Form1 : Form
{
int i = 0;
DateTime nowtime = new DateTime();
public Form1()
{
InitializeComponent();
}
[DllImport("kernel32.dll")]
private static extern bool SetLocalTime(ref SYSTEMTIME time);
[StructLayout(LayoutKind.Sequential)]
private struct SYSTEMTIME
{
public short year;
public short month;
public short day;
public short hour;
public short minute;
public short second;
}
public static void SetDate(DateTime dt)
{
SYSTEMTIME st;
st.year = (short)dt.Year;
st.month = (short)dt.Month;
st.day = (short)dt.Day;
st.hour = (short)(dt.Hour + 1);
st.minute = (short)(dt.Minute + 13);
st.second = (short)(dt.Second);
SetLocalTime(ref st);
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
nowtime = System.DateTime.Now;
SetDate(nowtime);
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}