DateTime

点击查看代码
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
  public static void Main()
  {
    var s = TimeSpan.FromHours(24);
    Console.WriteLine(s);                           // 1.00:00:00
    Console.WriteLine(DateTime.Now + s);            // 09/26/2023 09:59:24
    Console.WriteLine(DateTime.Now);                // 09/25/2023 09:56:03
    Console.WriteLine(DateTime.Now.AddHours(1) );   // 09/25/2023 10:59:24
    Console.WriteLine(DateTime.Now.AddHours(-1) );  // 09/25/2023 08:56:03
    Console.WriteLine(DateTime.Now -DateTime.Now.AddHours(-1));         // 01:00:00
    Console.WriteLine(DateTime.Now -DateTime.Now.AddHours(-1) > s);     // False
    Console.WriteLine(s.Days);                                          // 1
    Console.WriteLine(s.Hours);                                         // 0
    Console.WriteLine("**********************");
    Console.WriteLine(DateTime.Now.AddDays(-1));                        // 09/24/2023 09:59:24
    Console.WriteLine(DateTime.Now -DateTime.Now.AddDays(-1));          // 1.00:00:00
    Console.WriteLine(DateTime.Now -DateTime.Now.AddDays(-2) > s);      // True

  }

}

posted @ 2023-09-25 18:03  Cyber9527  阅读(20)  评论(0编辑  收藏  举报