通过日期获取星期几,通过日期获取凌晨、上午、中午、下午、晚上
根据
1: #region 根据时间计算上午 09:52 或者 晚上20:30
2: private enum DisTime { 凌晨 = 1, 早上, 上午, 中午, 下午, 晚上 };
3: public static string CaculateAmTm(DateTime sendTime)
4: {
5:
6: string s = null;
7: int i = sendTime.Hour;
8: if (0 <= i && i <= 4)
9: {
10: s = DisTime.凌晨.ToString();
11: }
12: if (4 <= i && i <= 9)
13: {
14: s = DisTime.早上.ToString();
15: }
16: if (9 <= i && i <= 11)
17: {
18: s = DisTime.上午.ToString();
19: }
20: if (12 <= i && i <= 12)
21: {
22: s = DisTime.中午.ToString();
23: }
24: if (12 <= i && i <= 19)
25: {
26: s = DisTime.下午.ToString();
27: }
28: if (19 <= i && i <= 23)
29: {
30: s = DisTime.晚上.ToString();
31: }
32: return (s + sendTime.ToString("HH:mm"));
33:
34:
35: }
36:
37: #endregion
38:
获取日期的年月日计算出是星期几
1: #region 根据年月日计算出是星期几
2:
3: /// <summary>
4: /// 根据年月日计算出是星期几
5: /// </summary>
6: /// <param name="year">年</param>
7: /// <param name="month">月</param>
8: /// <param name="day">日</param>
9: /// <returns></returns>
10: public static string CaculateWeekDay(int year, int month, int day)
11: {
12: if (month == 1)
13: {
14: month = 13;
15: year--;
16: }
17: if (month == 2)
18: {
19: month = 14;
20: year--;
21: }
22: int week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7 + 1;
23: string weekstr = "";
24: switch (week)
25: {
26: case 1:
27: weekstr = "星期一";
28: break;
29: case 2:
30: weekstr = "星期二";
31: break;
32: case 3:
33: weekstr = "星期三";
34: break;
35: case 4:
36: weekstr = "星期四";
37: break;
38: case 5:
39: weekstr = "星期五";
40: break;
41: case 6:
42: weekstr = "星期六";
43: break;
44: case 7:
45: weekstr = "星期日";
46: break;
47: }
48:
49: return weekstr;
50: }
51:
52: #endregion
53: