• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Change System Date using C#

mikaelmax99

Ad Placement Specialist
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
132
Likes
49
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
In this article, i will teach you how to create a program that will change the system date of your computer. This tutorial is very helpful to your program or system having this integration.


So, now let's start this tutorial!


1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application.

2. Next, add one DateTimePicker and and one button. You must design your interface like this:

date1_0.png


3. Import first the Runtime.InteropServices to access the DLL of the kernel32 in accessing the system date.
  1. using

    System.Runtime.InteropServices

    ;

Now, use a structure that will have the variables for the reference of our DLL.
  1. public

    struct

    SystemDate
  2. {
  3. public

    ushort

    Year;
  4. public

    ushort

    Month;
  5. public

    ushort

    DayOfWeek;
  6. public

    ushort

    Day;
  7. public

    ushort

    Hour;
  8. public

    ushort

    Minute;
  9. public

    ushort

    Second;
  10. public

    ushort

    Millisecond;
  11. }

    ;

  12. import the DLL now,
  13. <

    csharp>
  14. [

    DllImport(

    "kernel32.dll"

    , EntryPoint =

    "SetSystemTime"

    , SetLastError =

    true

    )

    ]
  15. public

    extern

    static

    bool

    Win32SetSystemTime(

    ref

    SystemDate sysDate)

    ;
  16. }

    ;

then put this code in your button to change directly the system date.
  1. private

    void

    button1_Click(

    object

    sender, EventArgs e)
  2. {
  3. SystemDate updatedTime =

    new

    SystemDate(

    )

    ;
  4. updatedTime.

    Month

    =

    (

    ushort

    )

    dateTimePicker1.

    Value

    .

    Month

    ;
  5. updatedTime.

    Day

    =

    (

    ushort

    )

    dateTimePicker1.

    Value

    .

    Day

    ;
  6. updatedTime.

    Year

    =

    (

    ushort

    )

    dateTimePicker1.

    Value

    .

    Year

    ;

  7. //this will update the date in your system date
  8. Win32SetSystemTime(

    ref

    updatedTime)

    ;


  9. MessageBox.

    Show

    (

    "The system date has changed!"

    , "Message"

    , MessageBoxButtons.

    OK

    , MessageBoxIcon.

    Information

    )

    ;
  10. }

Done!

Output:
date2_0.png


For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer

If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,499

350,639

350,649

Top