public static SYSTEMTIME FromDateTime(DateTime value) { SYSTEMTIME result = new SYSTEMTIME(); result.wYear = (short)value.Year; result.wMonth = (short)value.Month; result.wDayOfWeek = (short)value.DayOfWeek; result.wDay = (short)value.Day; result.wHour = (short)value.Hour; result.wMinute = (short)value.Minute; result.wSecond = (short)value.Second; result.wMilliseconds = (short)value.Millisecond; return result; }
// Set system time public void SetTime() { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME systime = new SYSTEMTIME(); GetSystemTime(ref systime); //DateTime datetime = TransmitTimestamp; // Thanks to Jim Hollenhorst <*****@*****.**> DateTime datetime = DateTime.Now.AddMilliseconds(LocalClockOffset).ToUniversalTime(); systime.wYear = (ushort)datetime.Year; systime.wMonth = (ushort)datetime.Month; systime.wDayOfWeek = (ushort)datetime.DayOfWeek; systime.wDay = (ushort)datetime.Day; systime.wHour = (ushort)datetime.Hour; systime.wMinute = (ushort)datetime.Minute; systime.wSecond = (ushort)datetime.Second; systime.wMilliseconds = (ushort)datetime.Millisecond; SetSystemTime(ref systime); }
public static extern bool SetSystemTime(ref SYSTEMTIME time);
public BLUETOOTH_DEVICE_INFO(long address) { dwSize = 560; Address = address; ulClassofDevice = 0; fConnected = false; fRemembered = false; fAuthenticated = false; stLastSeen = new SYSTEMTIME(); stLastUsed = new SYSTEMTIME(); #if DEBUG // The size is much smaller on CE (no times and string not inline) it // appears to ignore the bad dwSize value. So don't check this on CF. System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)) == dwSize, "BLUETOOTH_DEVICE_INFO SizeOf == dwSize"); #endif szName = ""; }
public bool SetSysTimeByStr(string timestr) { int temp = 0; SYSTEMTIME sysTime = new SYSTEMTIME(); //给sysTIme初始赋值 GetSystemTime(ref sysTime); string SysTime = timestr; sysTime.wYear = Convert.ToUInt16(SysTime.Substring(0, 4)); sysTime.wMonth = Convert.ToUInt16(SysTime.Substring(4, 2)); sysTime.wDay = Convert.ToUInt16(SysTime.Substring(6, 2)); sysTime.wHour = Convert.ToUInt16(SysTime.Substring(8, 2)); //为抵消北京时间+8而进行的操作 temp = Convert.ToInt16(SysTime.Substring(8, 2)) - 8; if (temp < 0) { sysTime.wHour = Convert.ToUInt16(temp + 24);//Convert.ToUInt16(SysTime.Substring(8,2))-Convert.ToInt16(8); sysTime.wDay = Convert.ToUInt16(sysTime.wDay - 1); if (sysTime.wDay == 0) { if (sysTime.wMonth == 5 | sysTime.wMonth == 7 | sysTime.wMonth == 8 | sysTime.wMonth == 10 | sysTime.wMonth == 12) { sysTime.wMonth = Convert.ToUInt16(sysTime.wMonth - 1); sysTime.wDay = Convert.ToUInt16(30); } else if (sysTime.wMonth == 1) { sysTime.wMonth = Convert.ToUInt16(12); sysTime.wDay = Convert.ToUInt16(31); sysTime.wYear = Convert.ToUInt16(sysTime.wYear - 1); } else if (sysTime.wMonth == 3) { sysTime.wMonth = Convert.ToUInt16(2); if (sysTime.wYear % 4 == 0 && sysTime.wYear % 100 != 0) sysTime.wDay = Convert.ToUInt16(29); else sysTime.wDay = Convert.ToUInt16(28); } else { sysTime.wMonth = Convert.ToUInt16(sysTime.wMonth - 1); sysTime.wDay = Convert.ToUInt16(31); } } } else { sysTime.wHour = Convert.ToUInt16(temp); } sysTime.wMinute = Convert.ToUInt16(SysTime.Substring(10, 2)); sysTime.wSecond = Convert.ToUInt16(SysTime.Substring(12, 2)); uint flag = SetSystemTime(ref sysTime); return Convert.ToBoolean(flag); }
public static extern bool SetLocalTime(ref SYSTEMTIME time);
public static extern void GetLocalTime(ref SYSTEMTIME theDateTime);
static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
/// <summary> /// STATIC: Convert to System.DateTime /// </summary> /// <param name="time"></param> /// <returns></returns> public static DateTime ToDateTime(SYSTEMTIME time) { return time.ToDateTime(); }
public static void SetTime(DateTime newUtcTime) { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME systime = new SYSTEMTIME(); GetSystemTime(ref systime); systime.wYear = (ushort)newUtcTime.Year; systime.wMonth = (ushort)newUtcTime.Month; systime.wDay = (ushort)newUtcTime.Day; systime.wHour = (ushort)newUtcTime.Hour; systime.wMinute = (ushort)newUtcTime.Minute; systime.wSecond = (ushort)newUtcTime.Second; systime.wMilliseconds = (ushort)newUtcTime.Millisecond; SetSystemTime(ref systime); }
/*{ return false; }*/ //Example public static void UpdateSystemTime(DateTime NewTime) { SYSTEMTIME st = new SYSTEMTIME(); st.FromDateTime(NewTime); //Call Win32 API to set time SetLocalTime(ref st); }
public void SetSystemDateFromDBServer() { DateTime d1 = GetDBDate(); string t1 = GetDBTime(); SYSTEMTIME CurDateTime = new SYSTEMTIME(); CurDateTime.wYear = short.Parse(d1.Year.ToString()) ; CurDateTime.wMonth = short.Parse(d1.Month.ToString()) ; CurDateTime.wDay = short.Parse(d1.Day.ToString()); string[] strsplit = t1.Split(':'); CurDateTime.wHour = short.Parse(strsplit[0]); CurDateTime.wMinute = short.Parse(strsplit[1]); CurDateTime.wSecond = short.Parse(strsplit[2]); SetLocalTime(ref CurDateTime); }
private static extern bool SetLocalTime(ref SYSTEMTIME time);
private static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
public static extern void GetSystemTime(ref SYSTEMTIME theDateTime);
private static extern uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
internal static extern bool FileTimeToSystemTime([In] ref FILETIME ft, [In, Out] ref SYSTEMTIME st);