C#根据期间编码PeriodId获取期间的日期范围
比如期间编码PeriodId=202308,获取该期间的日期范围:
BeginDate=2023/08/01
EndDate=2023/08/31
C# 全选
/// <summary>
/// 获取会计期的日期范围,如:periodId=202308,返回:2023-08-01,2023-08-31
/// </summary>
/// <param name="periodId"></param>
/// <param name="begin"></param>
/// <param name="end"></param>
public static void GetPeriodDateRange(string periodId, ref DateTime begin, ref DateTime end)
{
//202308
int year = Int32.Parse(periodId.GetLeft(4));
int month = Int32.Parse(periodId.GetRight(2));
int day = DateTime.DaysInMonth(year, month);
begin = new DateTime(year, month, 1);
end = new DateTime(year, month, day);
}
测试
C# 全选
DateTime startDate = DateTime.MinValue;
DateTime endDate = DateTime.MinValue;
var PeriodId = txt_PeriodId.EditValue.ToStringEx();
PeriodHelper.GetPeriodDateRange(PeriodId, ref startDate, ref endDate);
txtDateFrom.DateTime = startDate;
txtDateTo.DateTime = endDate;
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网