zoukankan      html  css  js  c++  java
  • winfrom 获取当前系统时间

    public class LibWrapDateTime
    		{
    			[DllImportAttribute( "Kernel32.dll" )]
    			public static extern void GetLocalTime(SystemTime st );
    			[DllImportAttribute( "Kernel32.dll" )]
    			public static extern void SetLocalTime(SystemTime st );
    		}
    		[StructLayoutAttribute( LayoutKind.Sequential)]
    
    public class SystemTime 
    		{
    			public ushort wYear; 
    			public ushort wMonth; 
    			public ushort wDayOfWeek; 
    			public ushort wDay; 
    			public ushort wHour; 
    			public ushort wMinute; 
    			public ushort wSecond; 
    			public ushort wMilliseconds; 
    		}
    		private void button1_Click(object sender, System.EventArgs e)
    		{//获取当前系统日期时间			
    		  DateTimePicker OlddateTimePicker = new DateTimePicker();		  
    		  this.textBox1.Text=OlddateTimePicker.Value.ToLongDateString().ToString();
              this.textBox1.Text+=OlddateTimePicker.Value.ToLongTimeString().ToString();		
    		 }
    
    		private void button2_Click(object sender, System.EventArgs e)
    		{//设置系统当前日期时间
    			if(MessageBox.Show("您真的确定更改系统当前日期时间吗?","信息提示",MessageBoxButtons.OK)==DialogResult.OK)
    			{
    				DateTime Year=this.dateTimePicker1.Value;
    				SystemTime MySystemTime = new SystemTime();
    				LibWrapDateTime.GetLocalTime(MySystemTime);
    				MySystemTime.wYear=(ushort)this.dateTimePicker1.Value.Year;
    				MySystemTime.wMonth=(ushort)this.dateTimePicker1.Value.Month;
    				MySystemTime.wDay=(ushort)this.dateTimePicker1.Value.Day;
    				MySystemTime.wHour=(ushort)this.dateTimePicker2.Value.Hour;
    				MySystemTime.wMinute=(ushort)this.dateTimePicker2.Value.Minute;
    				MySystemTime.wSecond=(ushort)this.dateTimePicker2.Value.Second;
    				LibWrapDateTime.SetLocalTime(MySystemTime);
    				button1_Click(null,null);
    			}
    		}
    
  • 相关阅读:
    ExtJS4 Panel中嵌套PDF
    从 JavaScript 数组去重谈性能优化(转)
    js中top、parent、frame
    “N”在Sql Server字段类型中的重要性 (转)
    IE下lineheight的BUG解决 (转)
    ExtJS4 Dialog
    Chrome启动后打开第一个网页很慢的解决方案(转)
    ExtJS4 Grid改变单元格背景颜色
    form表单
    Detect IFrame Load Event 探索Iframe的加载事件
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/14040511.html
Copyright © 2011-2022 走看看