如果当前月是十二月,那么如何查找下个月的第一天 [英] How to find the first day of next month,if the current month is december

查看:102
本文介绍了如果当前月是十二月,那么如何查找下个月的第一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下查询来获取下个月的数据。

I'm using the following query to get the next month.

int theMonth = ((System.DateTime)periodStartDate).Month+1;

但是,如果periodstartDate月id = s 12月,则以上语句会引发错误。

But if the periodstartDate month id=s december,the above statement throws error.

推荐答案

我认为您可以通过这种方式获得它

I think you can get it in this fashion

DateTime dt = new DateTime(2011,12,2);
DateTime dayone = new DateTime(dt.AddMonths(1).Year, dt.AddMonths(1).Month, 1);

现在您有一个正确的 DateTime 对象下个月的第一天,随便吧

Now you have a proper DateTime object to the first of the next month, do as you please with it

这篇关于如果当前月是十二月,那么如何查找下个月的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆