Link to home
Start Free TrialLog in
Avatar of colourblind82
colourblind82

asked on

Set System Time

Hi experts,

I have a question that needs your help. I need to set the system time using my software.

Therefore i used the SetSystemTime(lpSystemTime) Windows API.

However I can only set the year, month, day, minutes and seconds only.
I cannot set the hour to the time I want. For example, i set it to be 0 (which is suppose to set to 12 am) but the system time is changed to 8 am instead. There is an offset of 8 hours. when i set the time to be later, there might be a possibility that the day is changed to the following day.

How can i overcome this problem? Please advice.

Thx...

Colourblind82
Avatar of EDDYKT
EDDYKT
Flag of Canada image

I think you can just do

i.e.
Time = "10:06:37 PM"

to set time
Avatar of colourblind82
colourblind82

ASKER

Thanks

Like

Time = "hh:mm:ss AMPM"

and

Date = "mm/dd/yyyy"

but how about the Window API? If it is to be used in C++, what should i put in the parameters?
see this example
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 Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim lpSystemTime As SYSTEMTIME
    lpSystemTime.wYear = 2000
    lpSystemTime.wMonth = 1
    lpSystemTime.wDayOfWeek = -1
    lpSystemTime.wDay = 24
    lpSystemTime.wHour = 23
    lpSystemTime.wMinute = 26
    lpSystemTime.wSecond = 0
    lpSystemTime.wMilliseconds = 0
    'set the new time
    SetSystemTime lpSystemTime
I tried with the source codes that you provide but the system date is changed to 25 January 2000 7:26 AM instead. The hour is different and the day is changed to the following day. Has it got to do with my OS? I am using Window XP Home and Window 2000.
The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC).
please try this


dim s as string
s="time 23:00:00"
shell(s,0)                     'for changing time


s="date 12-30-2003"
shell(s,0)                      'for chenging date
try this

Dim MyTime, MyDate
MyTime = #4:35:17 PM#
Time = MyTime

MyDate = #10/10/2010#
Date = MyDate
Ok I can change the date and time using

Time = "hh:mm:ss AMPM"

and

Date = "mm/dd/yyyy"

can anyone tell me how to use SetSystemTime API so that the time and date is what i want. Or is there a better API to use?

ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial