注冊 登錄
Office中國論壇/Access中國論壇 返回首頁

的個人空間 http://m.mzhfr.cn/?0 [收藏] [復(fù)制] [分享] [RSS]

日志

API 設(shè)置調(diào)整系統(tǒng)當(dāng)前時間

已有 3069 次閱讀2008-4-28 13:36 |個人分類:API

對于時間要求比較嚴(yán)謹(jǐn)?shù)那闆r下,需要對當(dāng)前系統(tǒng)時間和外部時間作一個對比,并作相應(yīng)的調(diào)整,這就要求能對系統(tǒng)時間重新設(shè)置

CODE:


'**************************************************
'
' 功能: 重新設(shè)置系統(tǒng)時間
' 用法: SetTime "2008-4-26 22:53:48"
' 作者: andymark
'  QQ : 42503577 ; Email: ewang11@163.com
' 備注:
'
'**************************************************
'設(shè)置當(dāng)前系統(tǒng)時間
Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
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

'時區(qū)
Private Type TIME_ZONE_INFORMATION
        Bias As Long
        StandardName(32) As Integer
        StandardDate As SYSTEMTIME
        StandardBias As Long
        DaylightName(32) As Integer
        DaylightDate As SYSTEMTIME
        DaylightBias As Long
End Type

Public Sub SetTime(NewTime As String)
' 功能: 設(shè)置系統(tǒng)時間
   Dim lpSystemTime As SYSTEMTIME               '時間信息
   Dim ZoneNum As Integer
    ZoneNum = getZoneNum()
    With lpSystemTime
        .wYear = Year(NewTime)
        .wMonth = Month(NewTime) + 1
        .wDayOfWeek = -1
        .wDay = Day(NewTime)
        .wHour = Hour(NewTime) + ZoneNum
        .wMinute = Minute(NewTime)
        .wSecond = Second(NewTime)
        .wMilliseconds = 0
    End With
   
   SetSystemTime lpSystemTime
End Sub
Private Function getZoneNum() As Integer
    Dim lpSystemZone As TIME_ZONE_INFORMATION    '時區(qū)信息
    GetTimeZoneInformation lpSystemZone
    getZoneNum = lpSystemZone.Bias / 60
End Function
   

評論 (0 個評論)

facelist doodle 涂鴉板

您需要登錄后才可以評論 登錄 | 注冊

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-13 08:38 , Processed in 0.058910 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部