C# ローカルシステム時刻を設定直し
/// <summary>
///システム時間クラス
/// </summary>
[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;//秒
}
/// <summary>
/// Windows API
/// </summary>
public class WinAPI
{
[DllImport("Kernel32.dll")]
private static extern Boolean SetLocalTime([In, Out] SystemTime st);
/// <summary>
/// システム時刻をセット
/// </summary>
/// <param name="newdatetime">新しい時刻</param>
/// <returns></returns>
public static bool SetLocalTime(DateTime newdatetime)
{
SystemTime st = new SystemTime();
st.year = Convert.ToUInt16(newdatetime.Year);//年
st.month = Convert.ToUInt16(newdatetime.Month);//月
st.day = Convert.ToUInt16(newdatetime.Day);//日
st.hour = Convert.ToUInt16(newdatetime.Hour);//時
st.minute = Convert.ToUInt16(newdatetime.Minute);//分
st.second = Convert.ToUInt16(newdatetime.Second);//秒
return SetLocalTime(st);
}
}