1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Runtime.InteropServices;
- namespace Wayne.Lib
- {
- public class WayneSystemTimeCE : ISystemTime
- {
- public DateTime Now
- {
- get { return DateTime.Now; }
- }
- [DllImport("coredll.dll")]
- static extern bool SetSystemTime(
- ref SystemTime systemTime);
- [DllImport("coredll.dll")]
- static extern bool SetLocalTime(
- ref SystemTime systemTime);
- public void SetSystemTime(DateTime newTime)
- {
- SystemTime st = WayneSystemTime.ConvertToSystemTime(newTime.ToUniversalTime());
- bool rc = SetSystemTime(ref st);
- if (!rc)
- {
- int wrc = Marshal.GetLastWin32Error();
- throw new Exception("Error " + wrc + " setting system time");
- }
- }
- public void SetLocalTime(DateTime newTime)
- {
-
- SystemTime st = WayneSystemTime.ConvertToSystemTime(newTime);
- bool rc = SetLocalTime(ref st);
- if (!rc)
- {
- int wrc = Marshal.GetLastWin32Error();
- throw new Exception("Error " + wrc + " setting local time");
- }
- }
- }
- }
|