首页 > 学院 > 开发设计 > 正文

C# 调整系统时间

2019-11-17 04:08:02
字体:
来源:转载
供稿:网友
view plaincopy to clipboardPRint?
///调用API   
    [DllImport("kernel32.dll", SetLastError = true)]   
        public static extern int SetLocalTime(ref SystemTime lpSystemTime);   
  
  
  
/// 定义结构   
public struct SystemTime   
    {   
        public short wYear;   
        public short wMonth;   
        public short wDayOfWeek;   
        public short wDay;   
        public short wHour;   
        public short wMinute;   
        public short wSecond;   
        public short wMilliseconds;   
    }   
  
  
  
  
/// 调用   
            SystemTime systNew = new SystemTime();   
  
            // 设置属性    
            systNew.wDay =short.Parse( DateTime.Now.Day.ToString());   
            systNew.wMonth = short.Parse( DateTime.Now.Month.ToString());   
            systNew.wYear = 2004;   
            systNew.wHour = short.Parse(DateTime.Now.Hour.ToString());   
            systNew.wMinute = short.Parse( DateTime.Now.Minute.ToString());   
            systNew.wSecond = short.Parse( DateTime.Now.Second.ToString());   
  
            // 调用API,更新系统时间    
            SetLocalTime(ref systNew);  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表