DateTool.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //************************************************************************
  2. // author: yuzhengyang
  3. // date: 2017.8.17 - 2017.8.17
  4. // desc: 日期工具
  5. // Copyright (c) yuzhengyang. All rights reserved.
  6. //************************************************************************
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace Azylee.Core.DataUtils.DateTimeUtils
  12. {
  13. public sealed class DateTool
  14. {
  15. public static bool IsToday(DateTime date)
  16. {
  17. DateTime today = DateTime.Now;
  18. if (today.Year == date.Year && today.Month == date.Month && today.Day == date.Day)
  19. return true;
  20. return false;
  21. }
  22. public static bool IsYesterday(DateTime date)
  23. {
  24. DateTime yesterday = DateTime.Now.AddDays(-1);
  25. if (yesterday.Year == date.Year && yesterday.Month == date.Month && yesterday.Day == date.Day)
  26. return true;
  27. return false;
  28. }
  29. /// <summary>
  30. /// 当月有多少天
  31. /// </summary>
  32. /// <param name="year"></param>
  33. /// <param name="month"></param>
  34. /// <returns></returns>
  35. public static int MonthDays(int year, int month)
  36. {
  37. int days = 1;
  38. try
  39. {
  40. DateTime begin = new DateTime(year, month, 1);
  41. DateTime end = begin.AddMonths(1);
  42. days = (int)(end - begin).TotalDays;
  43. }
  44. catch { }
  45. return days;
  46. }
  47. }
  48. }