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);
    			}
    		}
    
  • 相关阅读:
    Centos7配置局域网yum源报错——Error downloading packages: failed to retrieve packages...
    Centos7扩展根分区——不增加磁盘
    Paxos算法
    记一次业务中的大坑-MYSQL有重复数据下的增加主键
    填坑之路——Hadoop分布式缓存
    Java接口技术
    Java-IO操作性能对比
    Clob对象转换为String
    剖析Reflection.getCallerClass
    Java类的加载、链接和初始化
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/14040511.html
Copyright © 2011-2022 走看看