|
@@ -0,0 +1,66 @@
|
|
1
|
+>关于年的问题
|
|
2
|
+- DownList显示年,可根据当前的年份,具体代码
|
|
3
|
+ ```
|
|
4
|
+ public List<string> GetYears()
|
|
5
|
+ {
|
|
6
|
+ List<string> allYears = new List<string>();
|
|
7
|
+ var now = DateTime.Now;
|
|
8
|
+ int currentYear = now.Year;//2019
|
|
9
|
+ allYears.Add((currentYear - 3).ToString());//2016
|
|
10
|
+ allYears.Add((currentYear - 2).ToString());//2017
|
|
11
|
+ allYears.Add((currentYear - 1).ToString());//2018
|
|
12
|
+ allYears.Add(currentYear.ToString());//2019
|
|
13
|
+ allYears.Add((currentYear + 1).ToString());//2020
|
|
14
|
+ allYears.Add((currentYear + 2).ToString());//2021
|
|
15
|
+ allYears.Add((currentYear + 3).ToString());//2022
|
|
16
|
+ return allYears;
|
|
17
|
+ }
|
|
18
|
+ ```
|
|
19
|
+
|
|
20
|
+> 关于月的问题
|
|
21
|
+- DownList显示月。因为月是具体的24个月,可直接增添值
|
|
22
|
+```
|
|
23
|
+ public List<string> GetMonths()
|
|
24
|
+ {
|
|
25
|
+ List<string> allMonths = new List<string>();
|
|
26
|
+ allMonths.AddRange(new List<string> { "01","02","03","04","05","06","07","08","09","10","11","12"});
|
|
27
|
+ return allMonths;
|
|
28
|
+ }
|
|
29
|
+```
|
|
30
|
+
|
|
31
|
+> 关于天的问题
|
|
32
|
+- 因为每年的每个月的天数不确定,可以根据请求或者选择的年月进行显示天数
|
|
33
|
+```
|
|
34
|
+/// <summary>
|
|
35
|
+ /// 获取天
|
|
36
|
+ /// </summary>
|
|
37
|
+ /// <param name="year"></param>
|
|
38
|
+ /// <param name="month"></param>
|
|
39
|
+ /// <returns></returns>
|
|
40
|
+ public List<string> GetDays(string year, string month)
|
|
41
|
+ {
|
|
42
|
+ var result = new List<string>();
|
|
43
|
+
|
|
44
|
+ if(!string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month))
|
|
45
|
+ {
|
|
46
|
+ //拼接月和年 2019-04
|
|
47
|
+ string yearAndMonthStr = year + "-" + month;
|
|
48
|
+ //月初 2019-04-01
|
|
49
|
+ DateTime beginTime = DateTime.Parse(yearAndMonthStr + "-01");
|
|
50
|
+ DateTime endTime = DateTime.Parse(beginTime.AddMonths(1).AddDays(-1).ToShortDateString());
|
|
51
|
+ //月末
|
|
52
|
+ for (DateTime dt = beginTime; dt <= endTime; dt = dt.AddDays(1))
|
|
53
|
+ {
|
|
54
|
+ result.Add(dt.Day.ToString());
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ return result;
|
|
59
|
+ }
|
|
60
|
+```
|
|
61
|
+> 时间格式转换(12或者24小时)
|
|
62
|
+```
|
|
63
|
+string time = Convert.ToDateTime(date).ToString("yyyy-MM-dd HH:mm");//HH为24小时
|
|
64
|
+string time = Convert.ToDateTime(date).ToString("yyyy-MM-dd hh:mm");//hh为12小时
|
|
65
|
+
|
|
66
|
+```
|