фиксы windows 7
This commit is contained in:
@@ -7,20 +7,39 @@ public abstract class WindowsTimeUtils
|
||||
// c# datetime set
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool SetSystemTime(ref SystemTime time);
|
||||
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern void GetSystemTime(ref SystemTime time);
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SystemTime(DateTime dt)
|
||||
public struct SystemTime
|
||||
{
|
||||
public ushort Year = (ushort)dt.Year;
|
||||
public ushort Month = (ushort)dt.Month;
|
||||
public ushort DayOfWeek = (ushort)dt.DayOfWeek;
|
||||
public ushort Day = (ushort)dt.Day;
|
||||
public ushort Hour = (ushort)dt.Hour;
|
||||
public ushort Minute = (ushort)dt.Minute;
|
||||
public ushort Second = (ushort)dt.Second;
|
||||
public ushort Milliseconds = (ushort)dt.Millisecond;
|
||||
public ushort Year, Month, DayOfWeek, Day;
|
||||
public ushort Hour, Minute, Second, Milliseconds;
|
||||
|
||||
public SystemTime() { }
|
||||
|
||||
public SystemTime(DateTime dt)
|
||||
{
|
||||
Year = (ushort)dt.Year;
|
||||
Month = (ushort)dt.Month;
|
||||
DayOfWeek = (ushort)dt.DayOfWeek;
|
||||
Day = (ushort)dt.Day;
|
||||
Hour = (ushort)dt.Hour;
|
||||
Minute = (ushort)dt.Minute;
|
||||
Second = (ushort)dt.Second;
|
||||
Milliseconds = (ushort)dt.Millisecond;
|
||||
}
|
||||
}
|
||||
|
||||
// Фикс для Windows 7 SP1 без обновлений
|
||||
// DataTime.Now использует слишком новый API
|
||||
public static DateTime Now()
|
||||
{
|
||||
var st = new SystemTime();
|
||||
GetSystemTime(ref st);
|
||||
return new DateTime(st.Year, st.Month, st.Day,
|
||||
st.Hour, st.Minute, st.Second, st.Milliseconds,
|
||||
DateTimeKind.Utc).ToLocalTime();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user