PDA中获得系统时间
来源:互联网 发布:热血江湖南林怪数据 编辑:程序博客网 时间:2024/06/08 16:26
在PDA中获得当前系统时间,开始时用System.DateTime.Now得到时间,可后来仔细一看,不对啊,时间相差一个小时,查了一下,也没弄清楚是什么原因,有弄清楚的,可以共享一下,后来我就改用了Wince中的API函数调用,才得到了正确的时间.(当然有的人也许考虑将时间加1,可我个人认为不托)
PDATime类
导入命名空间:using System.Runtime.InteropServices;
public class PDATime
{
[DllImport("coredll.dll")]
public static extern bool SetLocalTime(ref SYSTEMTIME Time);
[DllImport("coredll.dll")]
public static extern void GetLocalTime(ref SYSTEMTIME Time);
}
public struct 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;
/// <summary>
/// 从System.DateTime转换。
/// </summary>
/// <param name="time">System.DateTime类型的时间。</param>
public void FromDateTime(DateTime time)
{
wYear = (ushort)time.Year;
wMonth = (ushort)time.Month;
wDayOfWeek = (ushort)time.DayOfWeek;
wDay = (ushort)time.Day;
wHour = (ushort)time.Hour;
wMinute = (ushort)time.Minute;
wSecond = (ushort)time.Second;
//wMilliseconds = (ushort)time.Millisecond;
}
/// <summary>
/// 转换为System.DateTime类型。
/// </summary>
/// <returns></returns>
public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond);
}
/// <summary>
/// 静态方法。转换为System.DateTime类型。
/// </summary>
/// <param name="time">SYSTEMTIME类型的时间。</param>
/// <returns></returns>
public static DateTime ToDateTime(SYSTEMTIME time)
{
return time.ToDateTime();
}
}
使用:
SYSTEMTIME system = new SYSTEMTIME(); //结构体实例
hx_fj_mobile.entity.PDATime.GetLocalTime(ref system);//设置时间
this.label1.Text = system.ToDateTime().ToString();//显示当前时间
- PDA中获得系统时间
- 设置PDA系统日期时间
- C++中获得当前系统时间
- C++中获得当前系统时间
- C++中获得当前系统时间
- MFC中获得系统时间的方法
- MFC中获得系统时间的方法
- android中获得系统的时间
- 驱动中获得系统时间(转)
- MFC中获得系统时间的方法
- java中获得系统当前时间
- C++中获得当前系统时间
- C++中获得当前系统时间
- 在LabVIEW中如何获得系统时间
- MFC中获得系统时间的方法
- MFC中获得系统时间的方法
- 【java】:java中如何获得系统时间
- java 获得系统时间
- 强烈鄙视CSDN的blog编辑系统
- Using STL without exceptions in Visual Studio 2005
- 浮点数的表示
- 如何编写一个shell脚本
- webkit compile problem——std::exception::_Raise undefined symbol
- PDA中获得系统时间
- Image pyramids
- 科技的力量 - powercast sending power “through the air".
- winform 在不同的机子上显示不一样的解决
- ASP.NET 标准页页生命周期
- 在透明的Static控件上画透明的图标(icon)、图片
- PreparedStatement的用法(转)
- Reader PCSC Driver Error!You Must Reinstall Reader Driver!问题的解决办法
- java中的 break、continue 与 return