获取本周的周一和周日
代码
// 获取本周的周一
02. public string GetThisWeekMonday()
03. {
04. DateTime date = DateTime.Now;
05. DateTime first = System.DateTime.Now;
06. switch (date.DayOfWeek)
07. {
08. case System.DayOfWeek.Monday:
09. first = date;
10. break;
11. case System.DayOfWeek.Tuesday:
12. first = date.AddDays(-1);
13. break;
14. case System.DayOfWeek.Wednesday:
15. first = date.AddDays(-2);
16. break;
17. case System.DayOfWeek.Thursday:
18. first = date.AddDays(-3);
19. break;
20. case System.DayOfWeek.Friday:
21. first = date.AddDays(-4);
22. break;
23. case System.DayOfWeek.Saturday:
24. first = date.AddDays(-5);
25. break;
26. case System.DayOfWeek.Sunday:
27. first = date.AddDays(-6);
28. break;
29. }
30. return first.ToString("yyyy-MM-dd");
31. }
32.
33.
34. // 获取本周的周日
35. public string GetThisWeekSunday()
36. {
37. DateTime date = DateTime.Now;
38. DateTime last = System.DateTime.Now;
39. switch (date.DayOfWeek)
40. {
41. case System.DayOfWeek.Monday:
42. last = date.AddDays(6);
43. break;
44. case System.DayOfWeek.Tuesday:
45. last = date.AddDays(5);
46. break;
47. case System.DayOfWeek.Wednesday:
48. last = date.AddDays(4);
49. break;
50. case System.DayOfWeek.Thursday:
51. last = date.AddDays(3);
52. break;
53. case System.DayOfWeek.Friday:
54. last = date.AddDays(2);
55. break;
56. case System.DayOfWeek.Saturday:
57. last = date.AddDays(1);
58. break;
59. case System.DayOfWeek.Sunday:
60. last = date;
61. break;
62. }
63. return last.ToString("yyyy-MM-dd");
64. }
02. public string GetThisWeekMonday()
03. {
04. DateTime date = DateTime.Now;
05. DateTime first = System.DateTime.Now;
06. switch (date.DayOfWeek)
07. {
08. case System.DayOfWeek.Monday:
09. first = date;
10. break;
11. case System.DayOfWeek.Tuesday:
12. first = date.AddDays(-1);
13. break;
14. case System.DayOfWeek.Wednesday:
15. first = date.AddDays(-2);
16. break;
17. case System.DayOfWeek.Thursday:
18. first = date.AddDays(-3);
19. break;
20. case System.DayOfWeek.Friday:
21. first = date.AddDays(-4);
22. break;
23. case System.DayOfWeek.Saturday:
24. first = date.AddDays(-5);
25. break;
26. case System.DayOfWeek.Sunday:
27. first = date.AddDays(-6);
28. break;
29. }
30. return first.ToString("yyyy-MM-dd");
31. }
32.
33.
34. // 获取本周的周日
35. public string GetThisWeekSunday()
36. {
37. DateTime date = DateTime.Now;
38. DateTime last = System.DateTime.Now;
39. switch (date.DayOfWeek)
40. {
41. case System.DayOfWeek.Monday:
42. last = date.AddDays(6);
43. break;
44. case System.DayOfWeek.Tuesday:
45. last = date.AddDays(5);
46. break;
47. case System.DayOfWeek.Wednesday:
48. last = date.AddDays(4);
49. break;
50. case System.DayOfWeek.Thursday:
51. last = date.AddDays(3);
52. break;
53. case System.DayOfWeek.Friday:
54. last = date.AddDays(2);
55. break;
56. case System.DayOfWeek.Saturday:
57. last = date.AddDays(1);
58. break;
59. case System.DayOfWeek.Sunday:
60. last = date;
61. break;
62. }
63. return last.ToString("yyyy-MM-dd");
64. }