Example #1
0
        /// <summary>
        /// 获取系统时间
        /// </summary>
        /// <returns>系统当前时间</returns>
        public static DateTime GetSystemTime()
        {
            SystemDateTime st = new SystemDateTime();

            GetLocalTime(ref st);

            return(new DateTime(st.Year, st.Month, st.Day, st.Hour, st.Minute, st.Second, st.MilliSeconds));
        }
Example #2
0
        /// <summary>
        /// DateTime格式转换为SystemTime
        /// </summary>
        /// <param name="dt">DateTime格式时间</param>
        /// <returns>SystemTime格式时间</returns>
        public static SystemDateTime DataTimeToSystemTime(DateTime dt)
        {
            SystemDateTime st = new SystemDateTime();

            st.Year         = Convert.ToUInt16(dt.Year);
            st.Month        = Convert.ToUInt16(dt.Month);
            st.DayOfWeek    = Convert.ToUInt16(dt.DayOfWeek);
            st.Day          = Convert.ToUInt16(dt.Day);
            st.Hour         = Convert.ToUInt16(dt.Hour);
            st.Minute       = Convert.ToUInt16(dt.Minute);
            st.Second       = Convert.ToUInt16(dt.Second);
            st.MilliSeconds = Convert.ToUInt16(dt.Millisecond);
            return(st);
        }
Example #3
0
 private static extern void SetLocalTime(ref SystemDateTime st);
Example #4
0
 /// <summary>
 /// 同步本地时间
 /// </summary>
 /// <param name="st">时间字符串,字符串格式为:</param>
 public static void SetSystemTime(SystemDateTime st)
 {
     SetLocalTime(ref st);
 }
Example #5
0
        /// <summary>
        /// 同步本地事件
        /// </summary>
        /// <param name="dt">DateTime时间</param>
        public static void SetSystemTime(DateTime dt)
        {
            SystemDateTime st = SystemTime.DataTimeToSystemTime(dt);

            SetLocalTime(ref st);
        }