C# 时间修改器,修改系统本地时间

需要做c#.net 项目的,有时间并且想赚零花钱的老哥,请加Q群:741058172using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
需要做c#.net 项目的,有时间并且想赚零花钱的老哥,请加Q群:741058172namespace 时间修改
{
   
    internal class Program
    {
   

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool SetLocalTime(ref SystemTime st);

        [StructLayout(LayoutKind.Sequential)]
        public struct SystemTime
        {
   
            public ushort Year;
            public ushort Month;
            public ushort DayOfWeek;
            public ushort Day;
            public ushort Hour;
            public ushort Minute;
            public ushort Second;
            public ushort Milliseconds;
        }


        static void Main(string[] args)
        {
   

            Task.Run(() => {
   

                while (true)
                {
   
                    // 获取当前时间
                    DateTime now = DateTime.Now;

                    // 设置新的时间
                    DateTime newTime = new DateTime(2023, 5, 20, 8, 0, 0); // 设置为2023年12月31日早上8点

                    // 修改系统时间
                    SystemTime systemTime = new SystemTime();
                    systemTime.Year = (ushort)newTime.Year;
                    systemTime.Month = (ushort)newTime.Month;
                    systemTime.Day = (ushort)newTime.Day;
                    systemTime.Hour = (ushort)newTime.Hour;
                    systemTime.Minute = (ushort)newTime.Minute;
                    systemTime.Second = (ushort)newTime.Second;

                    if (SetLocalTime(ref systemTime))
                    {
   
                        Console.WriteLine("系统时间已修改为:" + newTime.ToString());
                    }
                    else
                    {
   
                        Console.WriteLine("修改系统时间失败!");
                    }
                }
            });
        }


    }
}

相关推荐

  1. C# 时间修改修改系统本地时间

    2024-01-01 00:32:04       33 阅读
  2. 安卓 修改系统时间

    2024-01-01 00:32:04       18 阅读
  3. 修改容器内部时间

    2024-01-01 00:32:04       6 阅读
  4. git修改版本发布时间

    2024-01-01 00:32:04       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-01 00:32:04       17 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-01 00:32:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-01 00:32:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-01 00:32:04       18 阅读

热门阅读

  1. GBASE南大通用-CodeFirst 模式

    2024-01-01 00:32:04       39 阅读
  2. 关于解决el-select组件自动清除数据空格的问题

    2024-01-01 00:32:04       33 阅读
  3. Linux: eBPF: bcc-tools:tcpdrop使用需要注意的问题

    2024-01-01 00:32:04       39 阅读
  4. 探索抖音详情API:塑造未来的媒体交互

    2024-01-01 00:32:04       40 阅读
  5. 第二百三十一回

    2024-01-01 00:32:04       39 阅读
  6. CSS实用功能

    2024-01-01 00:32:04       41 阅读
  7. Ubuntu20.04 防火墙配置

    2024-01-01 00:32:04       34 阅读
  8. 蓝牙技术在物联网中的应用

    2024-01-01 00:32:04       37 阅读