的Time Period Library for .NET包括類年與支持的財政時間段秒。
您可以定義具有自定義年份基準月的財務時間日曆。下面的示例使用月作爲財年開端:
// ------------------------------------------------------------------------
public class FiscalTimeCalendar : TimeCalendar
{
// ----------------------------------------------------------------------
public FiscalTimeCalendar() :
base(new TimeCalendarConfig
{
YearBaseMonth = YearMonth.October, // October year base month
YearWeekType = YearWeekType.Iso8601, // ISO 8601 week numbering
YearType = YearType.FiscalYear// treat years as fiscal years
})
{
} // FiscalTimeCalendar
} // class FiscalTimeCalendar
這就是用法: 收起
// ----------------------------------------------------------------------
public void FiscalYearSample()
{
FiscalTimeCalendar calendar = new FiscalTimeCalendar(); // use fiscal periods
DateTime moment1 = new DateTime(2006, 9, 30);
Console.WriteLine("Fiscal Year of {0}: {1}", moment1.ToShortDateString(),
new Year(moment1, calendar).YearName);
// > Fiscal Year of 30.09.2006: FY2005
Console.WriteLine("Fiscal Quarter of {0}: {1}", moment1.ToShortDateString(),
new Quarter(moment1, calendar).QuarterOfYearName);
// > Fiscal Quarter of 30.09.2006: FQ4 2005
DateTime moment2 = new DateTime(2006, 10, 1);
Console.WriteLine("Fiscal Year of {0}: {1}", moment2.ToShortDateString(),
new Year(moment2, calendar).YearName);
// > Fiscal Year of 01.10.2006: FY2006
Console.WriteLine("Fiscal Quarter of {0}: {1}", moment1.ToShortDateString(),
new Quarter(moment2, calendar).QuarterOfYearName);
// > Fiscal Quarter of 30.09.2006: FQ1 2006
} // FiscalYearSample
該庫還包括類Halfyear和季度與支持財政時間段。
只需檢查當前日期,如果它不到4月1日,那麼該年將是上一年,否則該年將是當年。 – Mudassir
編輯我的答案,當你編輯一些數據的問題,只是使用我寫的方法(我希望在VB是C#的確切翻譯...我是一個C#研究員) – balexandre
請你解釋你爲什麼要求4月1日和你的例子都會在4月30日迴歸?財政年度第一個歷月結束的意義何在? –