C#修改系统时间

[url]http://s.click.taobao.com/t_1?i=qzfZteiPVqr1Gw%3D%3D&p=mm_16303475_0_0&n=11[/url]


[StructLayout(LayoutKind.Sequential)]
class SystemTime
{
///
///系统时间类
///
public short Year;
public short Month;
public short DayOfWeek;
public short Day;
public short Hour;
public short Minute;
public short Second;
public short Milliseconds;
}
class WinApi
{
[DllImport("Kernel32.dll ")]
public static extern void SetSystemTime([In, Out] SystemTime st);
}
//设置时间
private void setTime(DateTime dt)
{
SystemTime st = new SystemTime();
st.Year = Convert.ToInt16(dt.Year);
st.Month = Convert.ToInt16(dt.Month);
st.DayOfWeek = Convert.ToInt16(dt.DayOfWeek);
st.Day = Convert.ToInt16(dt.Day);
st.Hour = Convert.ToInt16(dt.Hour);
st.Minute = Convert.ToInt16(dt.Minute);
st.Second = Convert.ToInt16(dt.Second);
st.Milliseconds = Convert.ToInt16(dt.Millisecond);
if (st.Hour >= 12)
{
st.Hour -= (short)8;
}
else if (st.Hour >= 8)
{
st.Hour -= (short)8;
}
else
{
st.Hour += (short)16;
}
WinApi.SetSystemTime(st);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值