要显示第二天,请使用AddDays()
方法和值+1获取第二天。
首先,使用以下命令获取当前日期-
DateTime.Today
现在,将1加到AddDays()
方法中以获取第二天-
DateTime.Today.AddDays(1)
以下是代码-
using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { Console.WriteLine("Today = {0}", DateTime.Today); Console.WriteLine("Previous Day = {0}", DateTime.Today.AddDays(-1)); Console.WriteLine("Next Day (Tomorrow) = {0}", DateTime.Today.AddDays(1)); } }
输出结果
Today = 9/4/2018 12:00:00 AM Previous Day = 9/3/2018 12:00:00 AM Next Day (Tomorrow) = 9/5/2018 12:00:00 AM