读取、设置系统时间日期
--------------------------------------------------------------------------------
作者:徐涛 时间:2005-1-15
有多种方法可以读取设置系统时间日期,现介绍两种简单的方法,第一种方法只能读取不能设置。
一、通过调用System.DateTime.Now来得到系统当前时间日期
MessageBox.Show(System.DateTime.Now.Year.ToString() +"-" + System.DateTime.Now.Month.ToString("#00") +"-" + System.DateTime.Now.Day.ToString("#00") +" " + System.DateTime.Now.DayOfWeek.ToString() +" " +System.DateTime.Now.Hour.ToString("#00") +":" + System.DateTime.Now.Minute.ToString("#00") +":" + System.DateTime.Now.Second.ToString("#00"));
二、通过自定义类来读取、设置系统时间日期
//引入名字空间
using System.Runtime.InteropServices
//申明
[DllImport( "Kernel32.dll" )]
public static extern void GetLocalTime(SystemTime st );
[DllImport( "Kernel32.dll" )]
public static extern void SetLocalTime(SystemTime st );
//定义时间日期类
public class SystemTimeDate
{
public ushort wYear;
public ushort wMonth;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载