Results 1 to 5 of 5

Thread: Changing SystemTime

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Changing SystemTime

    I am using basically the code below to accomplish my task. First, I store the current time in a systemtime type variable called restoretime. Next, I want to set the time to a predefined time that I select. Lastly, I want to restore the time that I saved in restoretime exactly as it was(progression of time is not an issue because my code runs very quickly).

    GetSystemTime(restoretime)
    retval = setsystemtime(newtime)
    ' code
    retval = setsystemtime(restoretime)

    The problem is the code does not work; for some reason I can not get the restoretime to be returned correctly. It may have to do with the timezone issue, and it may require I use the bias value from GetTimeZone information. If you know how I can accomplish what I am trying to do, I would greatly appreciate it. Thank you very much.
    Joe

  2. #2
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Send the whole code so someone can look and try to help.

    Regards.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    The whole code.....

    The only code crucial to fixing my problem deals with the API calls regarding time(restoretime and newttime are systemtime types)

    GetSystemTime(newtime)
    restoretime = newttime
    newtime.wYear = 'year
    newtime.wMonth = 'month
    'and so on
    retval = SetSystemTime(newtime)
    'executes a function
    retval = SetSystemTime(restoretime)

    Yet, the code does not restore the time I retrieved. In fact, it seems to quite randomly assign a time back. Any help would be much appreciated. Thank you

    Joe

  4. #4
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Code:
    Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
    Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
    
    Private restoretime 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 Command1_Click()
    
        Dim lpSystemTime As SYSTEMTIME
        lpSystemTime.wYear = Year(Now)
        lpSystemTime.wMonth = Month(Now)
        lpSystemTime.wDayOfWeek = -1
        lpSystemTime.wDay = Day(Now)
        lpSystemTime.wHour = Hour(Now)
        lpSystemTime.wMinute = Minute(Now)
        lpSystemTime.wSecond = Second(Now)
        'set the new time
        SetSystemTime lpSystemTime
        Me.Print "The New System Date is:" & lpSystemTime.wMonth & "-" & lpSystemTime.wDay & "-" & lpSystemTime.wYear
        Me.Print "The New System Time is:" & lpSystemTime.wHour & ":" & lpSystemTime.wMinute & ":" & lpSystemTime.wSecond
        
        'restore the time
        SetSystemTime restoretime
        Me.Print "The Restore System Date is:" & lpSystemTime.wMonth & "-" & lpSystemTime.wDay & "-" & lpSystemTime.wYear
        Me.Print "The Restore System Time is:" & lpSystemTime.wHour & ":" & lpSystemTime.wMinute & ":" & lpSystemTime.wSecond
        
    End Sub
    
    Private Sub Form_Load()
        Me.AutoRedraw = True
        
        'get the system time
        GetSystemTime restoretime
        Me.Print "The System Date is:" & restoretime.wMonth & "-" & restoretime.wDay & "-" & restoretime.wYear
        Me.Print "The System Time is:" & restoretime.wHour & ":" & restoretime.wMinute & ":" & restoretime.wSecond
    End Sub
    Hope this helps

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Thank you but...

    I wanted to actually track down to the millisecond. Luckily I found out what my problem was. If you want to know how I accomplished this, either reply to this post or email me at [email protected]

    Joe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width