.net – 计算2个日期之间的月数
发布时间:2020-12-17 07:14:24 所属栏目:百科 来源:网络整理
导读:我有以下VB.NET代码: Dim Date1 As New DateTime(2010,5,6)Dim Date2 As New DateTime(2009,10,12)Dim NumOfMonths = 0 ' This is where I am stumped 我想要做的是找出两个日期之间有多少个月.任何帮助,将不胜感激. 解决方法 这是您可以使用的方法: Publi
我有以下VB.NET代码:
Dim Date1 As New DateTime(2010,5,6) Dim Date2 As New DateTime(2009,10,12) Dim NumOfMonths = 0 ' This is where I am stumped 我想要做的是找出两个日期之间有多少个月.任何帮助,将不胜感激. 解决方法
这是您可以使用的方法:
Public Shared Function MonthDifference(ByVal first As DateTime,ByVal second As DateTime) As Integer Return Math.Abs((first.Month - second.Month) + 12 * (first.Year - second.Year)) End Function 像这样: Dim Date1 As New DateTime(2010,12) Dim NumOfMonths = MonthDifference(Date1,Date2) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 如何在$.ajax中覆盖jQuery对XMLHttpRequest的使用
- 用 Dojo 和 Ajax 创建可重用和可重新发布的组件
- Cilium使用 (Cilium 3)
- C#读取注册表:ProductID在x86目标应用程序中返回
- org.xml.sax.SAXParseException: Content is not
- 可能是最简单的正则教程
- ruby-on-rails – 运行rake资产:在测试之前预编
- c – 从QList中删除重复的对象
- ruby-on-rails – 如何RESTful更新has_and_belon
- cocos2dx中onExitTransitionDidStart、onExit和o
热点阅读