set the system time

Posted on 2004-11-25
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...
Question by:dotnet22
    LVL 10

    Assisted Solution

    See the following link

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

    Accepted Solution

    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);

                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);

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now