永发信息网

asp.net如何获取上月1号到上月的最后一天?

答案:2  悬赏:20  手机版
解决时间 2021-02-05 10:08
  • 提问者网友:無理詩人
  • 2021-02-05 01:18
asp.net如何获取上月1号到上月的最后一天?
最佳答案
  • 五星知识达人网友:一把行者刀
  • 2021-02-05 01:49
int year = DateTime.Now.Year;//当前年
int mouth = DateTime.Now.Month;//当前月

int beforeYear = 0;
int beforeMouth = 0;
if (mouth <= 1)//如果当前月是一月,那么年份就要减1
{
beforeYear = year - 1;
beforeMouth =12;//上个月
}
else
{
beforeYear = year;
beforeMouth = mouth - 1;//上个月
}
string beforeMouthOneDay = beforeYear + "年" + beforeMouth + "月" + 1 + "日";//上个月第一天
string beforeMouthLastDay = beforeYear + "年" + beforeMouth + "月" + DateTime.DaysInMonth(year, beforeMouth) + "日";//上个月最后一天
全部回答
  • 1楼网友:末日狂欢
  • 2021-02-05 02:18
1-先求得这个月一号的日期
dim td as datetime = now.year.tostring & "/" & now.month.tostring & "/01 00:00:00"
2-这个月一号的前一天就是上个月的最后一天
dim ttd as datetime = dateadd(dateInterval.day,-1,td)
ttd的值应该就是你想要的答案
还有,上个月的第一天的话,就是一号?・・・・
这个应该比较好求吧
取出上个月的年和月,然后后面加个01就可以吧
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯