Api示例:当地时间及格林尼治时间

发表于:2007-07-14来源:作者:点击数: 标签:
看看以下代码: 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
看看以下代码:  

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个时,这是因为中国在第八时区。你如果修改一下时区的话,可以看出时差在变化。(修改方法:双击系统拖盘区的时间->选择"时区"选项卡)  

原文转自:http://www.ltesting.net