SYSDATE.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace UAS_MES.PublicMethod
  7. {
  8. class SYSDATE
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public struct SYSTEMTIME
  14. {
  15. public ushort wYear;
  16. public ushort wMonth;
  17. public ushort wDayOfWeek;
  18. public ushort wDay;
  19. public ushort wHour;
  20. public ushort wMinute;
  21. public ushort wSecond;
  22. public ushort wMilliseconds;
  23. /// <summary>
  24. /// 从System.DateTime转换。
  25. /// </summary>
  26. /// <param name="time">System.DateTime类型的时间。</param>
  27. public void FromDateTime(DateTime time)
  28. {
  29. wYear = (ushort)time.Year;
  30. wMonth = (ushort)time.Month;
  31. wDayOfWeek = (ushort)time.DayOfWeek;
  32. wDay = (ushort)time.Day;
  33. wHour = (ushort)time.Hour;
  34. wMinute = (ushort)time.Minute;
  35. wSecond = (ushort)time.Second;
  36. wMilliseconds = (ushort)time.Millisecond;
  37. }
  38. /// <summary>
  39. /// 转换为System.DateTime类型。
  40. /// </summary>
  41. /// <returns></returns>
  42. public DateTime ToDateTime()
  43. {
  44. return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond, wMilliseconds);
  45. }
  46. /// <summary>
  47. /// 静态方法。转换为System.DateTime类型。
  48. /// </summary>
  49. /// <param name="time">SYSTEMTIME类型的时间。</param>
  50. /// <returns></returns>
  51. public static DateTime ToDateTime(SYSTEMTIME time)
  52. {
  53. return time.ToDateTime();
  54. }
  55. }
  56. public class Win32API
  57. {
  58. [DllImport("Kernel32.dll")]
  59. public static extern bool SetLocalTime(ref SYSTEMTIME Time);
  60. [DllImport("Kernel32.dll")]
  61. public static extern void GetLocalTime(ref SYSTEMTIME Time);
  62. }
  63. }
  64. }