C # modify the local time and obtain the hard disk serial number

Source: Internet
Author: User

Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Runtime. InteropServices;

Namespace Fengyun
{
Public class Win32
{
# Region modify local system time
[DllImport ("Kernel32.dll")]
Private extern static void GetSystemTime (ref SYSTEMTIME lpSystemTime );

[DllImport ("Kernel32.dll")]
Private extern static uint SetLocalTime (ref SYSTEMTIME lpSystemTime );

[StructLayout (LayoutKind. Sequential)]
Private 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;
}

/// <Summary>
/// Synchronize the local time with the SQL server time
/// </Summary>
/// <Param name = "SqlServerTime"> time </param>
Public static void SetTime (DateTime SqlServerTime)
{
SYSTEMTIME st = new SYSTEMTIME ();
St. wYear = Convert. ToUInt16 (SqlServerTime. Year );
St. wMonth = Convert. ToUInt16 (SqlServerTime. Month );
St. wDay = Convert. ToUInt16 (SqlServerTime. Day );
St. wHour = Convert. ToUInt16 (SqlServerTime. Hour );
St. wMilliseconds = Convert. ToUInt16 (SqlServerTime. Millisecond );
St. wMinute = Convert. ToUInt16 (SqlServerTime. Minute );

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.