[ZT] Two Methods for modifying the system time using. net

Source: Internet
Author: User

Two methods:
1. You can use APIs to do the following:
[Structlayout (layoutkind. Sequential)]
Public struct systemtime
{
Public short year;
Public short month;
Public short dayofweek;
Public short day;
Public short hour;
Public short minute;
Public short second;
Public short miliseconds;
}

// API function declaration
[Dllimport ("kernel32.dll", charset = charset. ANSI)]
Public extern static bool setsystemtime (ref systemtime time );

Private void button#click (Object sender, system. eventargs E)
{
// Call the code
Systemtime T = new systemtime ();
T. Year = 2000;
T. month = 1;
T. Day = 2;
T. hour = 12-8; // This function uses the time zone 0. For the time zone + 8, you must calculate the time. if you want to set 12 points, it is 12-8
T. Minute = 5;
Bool v = setsystemtime (ref t );
Console. writeline (V. tostring ());
}

2. The VB.net method is simple.
Today = Date
Timeofday = Time

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.