C#内网NTP时间同步源码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Diagnostics;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime aa = MGetNetworkTime();
textBox1.Text = aa.ToString("yyyy-MM-dd HH:mm:ss");
if (textBox1.Text == "1900-12-31 00:00:00")
{ }
else {
string times = aa.ToString("yyyy-MM-dd HH:mm:ss");
DateTimeSynchronization dt = new DateTimeSynchronization();
if (dt.SetLocalTimeByStr(times))
{
MessageBox.Show("修改成功");
}
else
{
MessageBox.Show("修改失败");
}
}
}
public DateTime MGetNetworkTime()
{
try
{
//default Windows time server


782

被折叠的 条评论
为什么被折叠?



