Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

set the system time

Posted on 2004-11-25
2
Medium Priority
?
221 Views
Last Modified: 2010-04-15
Is there a way to change the system time? Basically the system tray clock because when the application I have synchronizes with a time server, it needs to be able to set the system clock...
0
Comment
Question by:dotnet22
2 Comments
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 1000 total points
ID: 12678697
See the following link

http://www.dotnet247.com/247reference/msgs/38/192848.aspx

It tells about using the SetSystemTime function in Kernel32.dll
0
 
LVL 6

Accepted Solution

by:
Chester_M_Ragel earned 1000 total points
ID: 12678891
Here is a sample code,

using System;
using System.Runtime.InteropServices;

namespace MyBD
{
      struct SystemTime
      {
            public short wYear;
            public short wMonth;
            public short wDayOfWeek;
            public short wDay;
            public short wHour;
            public short wMinute;
            public short wSecond;
            public short wMilliseconds;
      }

      class SystemTimeSetter
      {
            
            [DllImport("kernel32.dll", SetLastError=true)] static extern int SetSystemTime (ref SystemTime lpSystemTime);

            [STAThread]
            static void Main(string[] args)
            {
                  SystemTime lpSystemTime;
                  lpSystemTime.wYear = 1979;
                  lpSystemTime.wMonth = 8;
                  lpSystemTime.wDayOfWeek = -1;
                  lpSystemTime.wDay = 3;
                  lpSystemTime.wHour = 0;
                  lpSystemTime.wMinute = 0;
                  lpSystemTime.wSecond = 0;
                  lpSystemTime.wMilliseconds = 0;
                  SetSystemTime(ref lpSystemTime);
            }
      }
}
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

580 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