获得昨天的日期,今天的日期,明天的日期

 1、昨天的年

DateTime.Now.AddDays(-1).Year

昨天的月份

DateTime.Now.AddDays(-1).Month

昨天的额日期

DateTime.Now.AddDays(-1).Day

2、今天的年

DateTime.Now.Year

今天的月份

DateTime.Now.Month

今天的日期

DateTime.Now.Day

3、明天的年

DateTime.Now.AddDays(1).Year

明天的月份

DateTime.Now.AddDays(1).Month

明天的日期

DateTime.Now.AddDays(1).Day

        int[] year = new int[] { DateTime.Now.AddDays(-1).Year, DateTime.Now.Year , DateTime.Now.AddDays(1).Year};
        int[] month = new int[] { DateTime.Now.AddDays(-1).Month, DateTime.Now.Month,DateTime.Now.AddDays(1).Month };
        int[] day = new int[] { DateTime.Now.AddDays(-1).Day, DateTime.Now.Day, DateTime.Now.AddDays(1).Day };
        for (int i = 0; i < year.Length; i++)
        {
            Debug.Log("时间" + year[i] + "年" + month[i] + "月" + day[i] + "日");
        }

猜你喜欢

转载自blog.csdn.net/wk201403010114/article/details/87981878