设置PDA系统日期时间
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
设置PDA系统日期时间
c#例子1
1using System;
2using System.Runtime.InteropServices;
3
4class SysDateTime
5{
6private struct SYSTEMTIME
7 {
8public ushort wYear;
9public ushort wMonth;
10public ushort wDayOfWeek;
11public ushort wDay;
12public ushort wHour;
13public ushort wMinute;
14public ushort wSecond;
15public ushort wMilliseconds;
16 }
17
18 [DllImport("Coredll.dll")]
19private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
20
21public static void SetDateTime(DateTime dt)
22 {
23#region Codes========================================================== 24
25 SYSTEMTIME sysTime = new SYSTEMTIME();
26
27 sysTime.wYear = Convert.ToUInt16(dt.Year);
28 sysTime.wMonth = Convert.ToUInt16(dt.Month);
29 sysTime.wDay = Convert.ToUInt16(dt.Day);
30 sysTime.wDayOfWeek = Convert.ToUInt16(dt.DayOfWeek);
31 sysTime.wHour = Convert.ToUInt16(dt.Hour);
32 sysTime.wMinute = Convert.ToUInt16(dt.Minute);
33 sysTime.wSecond = Convert.ToUInt16(dt.Second);
34 sysTime.wMilliseconds = Convert.ToUInt16(lisecond);
35
36 SetLocalTime(ref sysTime);
37
38#endregion
39 }
40} // class
C#例子2:
using System;
using System.Runtime.InteropServices;
namespace setlocaltime
{
class Systemtime
{
[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;
///
/// 从System.DateTime转换。
///
/// System.DateTime类型的时间。 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)lisecond;
}
///
/// 转换为System.DateTime类型。
///
///
public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond, wMilliseconds);
}
///
/// 静态方法。转换为System.DateTime类型。
///
/// SYSTEMTIME类型的时间。
///
public static DateTime ToDateTime(SYSTEMTIME time)
{
return time.ToDateTime();
}
}
}
做的例子
Imports System
Imports System.Runtime.InteropServices
Public Class Form1
Private Structure SYSTEMTIME
Public wYear As UShort
Public wMonth As UShort
Public wDayOfWeek As UShort
Public wDay As UShort
Public wHour As UShort
Public wMinute As UShort
Public wSecond As UShort
Public wMilliseconds As UShort
End Structure
Private Shared Function SetLocalTime(ByRef T1 As SYSTEMTIME) As Boolean
End Function