c#生成年,年月,年月日,季度,周类型日期。

这篇博客介绍了如何使用C#生成不同类型的日期,包括年份、年月、年月日、季度和周。通过GetYearMonthList、GetYearQuarterList、GetYearDayList、GetYearWeekList和GetYBookYearList等方法,可以获取过去和未来的日期组合,方便在日期选择场景中使用。
摘要由CSDN通过智能技术生成
public static List<PatternInfo> GetYearMonthList(int type = 1)
        {
            List<PatternInfo> rList = new List<PatternInfo>();
            DateTime curTime = DateTime.Now.AddMonths((type == 1 ? -1 : 0));
            rList.Add(new PatternInfo()
            {
                PatternCode = "-1",
                PatternName = "--请选择--"
            });
            int cYear = curTime.Year;
            int cMonth = curTime.Month;
            for (int i = 0; i <= 10; i++)
            {
                for (int j = cMonth; j > 0; j--)
                {
                    PatternInfo _curMonthInfo = new PatternInfo();
                    _curMonthInfo.PatternCode = string.Format("{0}{1}", cYear, (j < 10 ? "0" + j.ToString() : j.ToString()));
                    _curMonthInfo.PatternName = string.Format("{0}{1}", cYear, (j < 10 ? "0" + j.ToString() : j.ToString()));
                    rList.Add(_curMonthInfo);
                }
                cYear--;
                cMonth = 12;
            }
            return rList;
        }
        public static List<PatternInfo> GetYearQuarterList(int 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值