gpt4 book ai didi

Vb.net 当前日期减去日期

转载 作者:行者123 更新时间:2023-12-04 18:13:32 24 4
gpt4 key购买 nike

可以说我的日期是:

    Dim theDate As DateTime = DateTime.ParseExact("2013-04-10 21:34 PM", "yyyy-MM-dd HH:mm tt", CultureInfo.InvariantCulture)

我使用这种格式:
"yyyy-MM-dd HH:mm tt"

我想获取当前日期并执行以下操作:
Dim theDate As DateTime = DateTime.ParseExact("2013-04-10 21:34 PM", "yyyy-MM-dd HH:mm tt", CultureInfo.InvariantCulture)
Dim currentTime As System.DateTime = System.DateTime.Now
dim Result as new datetime
Result = currentTime.Date - theDate

更新:

我试过了:
Dim currentTime As System.DateTime = System.DateTime.Now
Dim date1 As New System.DateTime(2013, 4, 10, 21, 34, 10)
Dim date2 As New System.DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second)
Dim diff1 As System.TimeSpan
diff1 = date2.Subtract(date1)
MsgBox(diff1.ToString)

最佳答案

一个 TimeSpan将允许您减去日期。

DateTime.Subtract Method (TimeSpan)

Dim date1 As New System.DateTime(1996, 6, 3, 22, 15, 0)
Dim date2 As New System.DateTime(1996, 12, 6, 13, 2, 0)

Dim diff1 As System.TimeSpan
' diff1 gets 185 days, 14 hours, and 47 minutes.
diff1 = date2.Subtract(date1)

MsgBox(diff1.Days)
MsgBox(diff1.Hours)
MsgBox(diff1.Minutes)

这里是所有 members of the TimeSpan class

关于Vb.net 当前日期减去日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com