Change System Time & amp; in C # to be notified of system time change

Source: Internet
Author: User

1. Change System Time
C # System. the DateTime class encapsulates the date and time, which is convenient for time conversion and processing, but I have not found any member in it that can be used to modify the system time. Friends who have used VC and VB may know that we can call Win32 API SetLocalTime to change the system time. It seems that C # can only do this. SetLocalTime requires a SYSTEMTIME structure pointer as a parameter, which is not difficult. We can quickly define this structure in C #, but the problem is, I also want to "enjoy ".. NET Framework System. what should I do if DateTime is convenient in time conversion and processing? You only need to do it yourself. Compile a member function for SYSTEMTIME in C # to convert the function to System. DateTime. See the following code:
First, I created a new C # file to facilitate future calls, put the SetLocalTime API in a class named Win32API, and put the class in my own namespace, avoid Name Conflict. In the future, I can add frequently-used APIs to this class and namespace to construct my own C # Win32 API function library J.
// Forproc_Win32.cs
// Declare common Win32 API functions and structures
Using System;
Using System. Runtime. InteropServices;
 
Namespace Farproc. Win32
{
/// <Summary>
///
/// </Summary>
Public struct SYSTEMTIME
{
Public ushort wYear;
Public ushort wMonth;
Public ushort wDayOfWeek;
Public ushort wDay;
Public ushort wHour;
Public ushort wMinute;
Public ushort wSecond;
Public ushort wMilliseconds;

Related Article

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.