T
trant
I am trying to set my system time using C#.
I use the P Invoke method as described on MSDN web site.
All the fields are set properly except for one: hour.
For example I set it to a value of 15 and that somehow becomes 11 am on the
clock.
Here is my code:
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort year;
public ushort month;
public ushort dayOfWeek;
public ushort day;
public ushort hour;
public ushort minute;
public ushort second;
public ushort milli;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetSystemTime([In] ref SYSTEMTIME st);
SYSTEMTIME systime = new SYSTEMTIME();
// set fields ....
// i.e. :
systime.hour = 15;
SetSystemTime(ref systime);
System time gets updated but hour is 4 hours off what I set.
I dont see any way to specify timezone so it can't be that... what gives? I
got the order of the fields correct in the struct, don't I?
I use the P Invoke method as described on MSDN web site.
All the fields are set properly except for one: hour.
For example I set it to a value of 15 and that somehow becomes 11 am on the
clock.
Here is my code:
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort year;
public ushort month;
public ushort dayOfWeek;
public ushort day;
public ushort hour;
public ushort minute;
public ushort second;
public ushort milli;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetSystemTime([In] ref SYSTEMTIME st);
SYSTEMTIME systime = new SYSTEMTIME();
// set fields ....
// i.e. :
systime.hour = 15;
SetSystemTime(ref systime);
System time gets updated but hour is 4 hours off what I set.
I dont see any way to specify timezone so it can't be that... what gives? I
got the order of the fields correct in the struct, don't I?