C# 比较日期格式中的年月大小


需求比较两个DateTime类型的年月

类似:只能是当月或当月之前的数据(只能是1号)

 

思路:将两个需要对比的日期 全部转换成月份 再做比较   

   如:DateTime dt_Now=new DateTime.Now();

  string dt_other="2020-03-02";

  DateTime othertime = DateTime.Parse(dt_other);//转换日期

  int now_Month = dtNow.Year * 12 + dtNow.Month;

  int other_Month = dt_other.Year * 12 + dt_other.Month;

比较 now_Month 和 other_Month 大小即可。

代码并未实现以上需求 仅记录思路。

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM