Change system time && get system time change notification in C #
Source: Internet
Author: User
First, change the system time
C # 's System.DateTime class provides an encapsulation of datetime, which is convenient for time conversion and processing, but I don't find any members in it that can be used to modify the system time. VC, VB and other friends may know that we can call the Win32 API setlocaltime to change the system time, it seems that C # can only be so. Setlocaltime need a SYSTEMTIME structure pointer as a parameter, it's not difficult, we can "Bishi" quickly define this structure in C #, but the problem is, I also want to "enjoy". NET What about the convenience of the System.DateTime of the framework in terms of time conversion and processing? Only do-it-yourself, for our C # systemtime to write member functions, to achieve and system.datetime between the interchange. Take a look at the following code:
First of all, I created a C # file in order to invoke it later, put the Setlocaltime API inside a class called Win32API, and put this class in my own defined namespace to avoid name collisions. I can also continue to add common APIs to this class and namespace in order to construct my own C # Win32 API function Library J
Forproc_win32.cs
Declarations of 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;
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