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);
    			}
    		}
    
  • 相关阅读:
    MVC三层架构学习总结实例
    JSON & Ajax
    设计模式之单例模式
    设计模式之静态工厂方法
    Gitee 添加了ssh公钥还是需要账户和密码
    MySQL日期时间函数大全[转]
    session 注意事项
    session 入库2 垃圾回收机制
    session 入库的实现
    PHP实现手机号码中间四位用星号(*)隐藏的自定义函数分享
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/14040511.html
Copyright © 2011-2022 走看看