Api示例:当地时间及格林尼治时间
【打印文章】
看看以下代码:
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Sub Form_Load()
Dim LocalTime As SYSTEMTIME
Dim SysTime As SYSTEMTIME
'必须设为True,否则无法显示下面打印的字符
Me.AutoRedraw = True
'取得但前时区的时间
GetLocalTime LocalTime
'取得系统的时间。即格林尼治时间。
GetSystemTime SysTime
Me.Print
Me.Print "当地日期:" & LocalTime.wYear; "年" & LocalTime.wMonth & "月" & LocalTime.wDay & "日"
Me.Print "当地时间:" & LocalTime.wHour & ":" & LocalTime.wMinute & ":" & LocalTime.wSecond
Me.Print "格林尼治日期:" & SysTime.wYear; "年" & SysTime.wMonth & "月" & SysTime.wDay & "日"
Me.Print "格林尼治时间:" & SysTime.wHour & ":" & SysTime.wMinute & ":" & SysTime.wSecond
End Sub
如果没有猜错的话,显示出来的时间相差8个时,这是因为中国在第八时区。你如果修改一下时区的话,可以看出时差在变化。(修改方法:双击系统拖盘区的时间->选择"时区"选项卡)
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Sub Form_Load()
Dim LocalTime As SYSTEMTIME
Dim SysTime As SYSTEMTIME
'必须设为True,否则无法显示下面打印的字符
Me.AutoRedraw = True
'取得但前时区的时间
GetLocalTime LocalTime
'取得系统的时间。即格林尼治时间。
GetSystemTime SysTime
Me.Print
Me.Print "当地日期:" & LocalTime.wYear; "年" & LocalTime.wMonth & "月" & LocalTime.wDay & "日"
Me.Print "当地时间:" & LocalTime.wHour & ":" & LocalTime.wMinute & ":" & LocalTime.wSecond
Me.Print "格林尼治日期:" & SysTime.wYear; "年" & SysTime.wMonth & "月" & SysTime.wDay & "日"
Me.Print "格林尼治时间:" & SysTime.wHour & ":" & SysTime.wMinute & ":" & SysTime.wSecond
End Sub
如果没有猜错的话,显示出来的时间相差8个时,这是因为中国在第八时区。你如果修改一下时区的话,可以看出时差在变化。(修改方法:双击系统拖盘区的时间->选择"时区"选项卡)
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】