日期格式换算

DateTime dtTarget = DateTime.Now;
//日
dtTarget.ToShortDateString();

//月                 
dtTarget.AddDays(-DateTime.Now.Day + 1).ToShortDateString();
dtTarget.AddMonths(1).AddDays(-dtTarget.AddMonths(1).Day).ToShortDateString();

//季度
DateTime startQuarter = dtTarget.AddMonths(0 - (dtTarget.Month - 1) % 3).AddDays(1 - dtTarget.Day);  //本季度初
startQuarter.ToShortDateString();
DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1);  //本季度末
endQuarter.ToShortDateString();

//年
dtTarget.Year.ToString() + "-01-01";
dtTarget.Year.ToString() + "-12-31";

  

posted @ 2017-03-21 16:43  哈佛  阅读(242)  评论(0编辑  收藏  举报