?
Solved

Set System Time

Posted on 2003-11-06
10
Medium Priority
?
753 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:colourblind82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9698644
I think you can just do

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

to set time
0
 

Author Comment

by:colourblind82
ID: 9698875
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?
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9699082
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:colourblind82
ID: 9705256
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.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9706803
The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC).
0
 

Expert Comment

by:anoop_chekkattu
ID: 9717070
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
0
 

Expert Comment

by:anoop_chekkattu
ID: 9717134
sorry..
0
 

Expert Comment

by:anoop_chekkattu
ID: 9717208
try this

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

MyDate = #10/10/2010#
Date = MyDate
0
 

Author Comment

by:colourblind82
ID: 9719836
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?

0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 150 total points
ID: 9721663
You have subract the UTC hour and local hour different from the struct

use this to get system time and you will know the hour differenet

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()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'KPDTeam@Allapi.net
    Dim SysTime As SYSTEMTIME
    'Set the graphical mode to persistent
    Me.AutoRedraw = True
    'Get the system time
    GetSystemTime SysTime
    'Print it to the form
    Me.Print "The System Date is:" & SysTime.wMonth & "-" & SysTime.wDay & "-" & SysTime.wYear
    Me.Print "The System Time is:" & SysTime.wHour & ":" & SysTime.wMinute & ":" & SysTime.wSecond
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question