[讨论] 计算星期几的C代码

SuperStar515   2007-7-6 20:49 楼主
计算星期几的C代码
计算星期几的C代码
  1. static UCHAR ClkDay; /* Counters for local
  2. DATE */
  3. static UCHAR ClkDOW; /* Day of week (0 is
  4. Sunday) */
  5. static UCHAR ClkMonth;
  6. static UINT ClkYear;
  7. typedef struct clk_month
  8. {
  9. UCHAR MonthDays; /* Number of days in each
  10. month */
  11. char *MonthName; /* Name of the
  12. month */
  13. UCHAR MonthVal; /* Value used to compute day of the
  14. week */
  15. } CLK_MONTH;
  16. static CLK_MONTH code ClkMonthTbl[] = { /* MONTHS
  17. TABLE */
  18. {0, "", 0}, /* Invalid
  19. month */
  20. {31, "January ", 6}, /*
  21. January */
  22. {28, "February ", 2}, /* February (note leap years are handled
  23. by code) */
  24. {31, "March ", 2}, /*
  25. March */
  26. {30, "April ", 5}, /*
  27. April */
  28. {31, "May ", 0}, /*
  29. May */
  30. {30, "June ", 3}, /*
  31. June */
  32. {31, "July ", 5}, /*
  33. July */
  34. {31, "August ", 1}, /*
  35. August */
  36. {30, "September ", 4}, /*
  37. September */
  38. {31, "October ", 6}, /*
  39. October */
  40. {30, "November ", 2}, /*
  41. November */
  42. {31, "December ", 4} /*
  43. December */
  44. };
  45. /*
  46. ********************************************************************************
  47. *************************
  48. * COMPUTE DAY-OF-WEEK
  49. *
  50. * Description : This function computes the day of the week (0 == Sunday) based
  51. on the current month,
  52. * day and year.
  53. * Arguments : None.
  54. * Returns : None.
  55. * Notes : - This function updates ClkDOW.
  56. * - This function is called by ClkUpdateDate().
  57. ********************************************************************************
  58. *************************
  59. */
  60. #if CLK_DATE_EN
  61. static void ClkUpdateDOW (void)
  62. {
  63. UINT dow;
  64. dow = ClkDay + ClkMonthTbl[ClkMonth].MonthVal;
  65. if (ClkMonth < 3)
  66. {
  67. if (ClkIsLeapYear(ClkYear))
  68. {
  69. dow--;
  70. }
  71. }
  72. dow += ClkYear + (ClkYear / 4);
  73. dow += (ClkYear / 400) - (ClkYear / 100);
  74. dow %= 7;
  75. ClkDOW = dow;
  76. }
  77. #endif
世界是个圈,人生也是个圈。

回复评论 (2)

回复:计算星期几的C代码

好, 虽然我不懂用C,但还是要支持楼主的精神~~~~
点赞  2007-7-8 01:32

回复:计算星期几的C代码

用不着那么复杂~~~~~~~~~~~~~~ 我
点赞  2007-7-8 12:10
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复