gpt4 book ai didi

vb.net - 如何使用 vb.net 获取一年中的总小时数?

转载 作者:行者123 更新时间:2023-12-02 05:17:50 26 4
gpt4 key购买 nike

我想使用 VB.Net 获取一年中的总小时数。有什么方法或功能可以帮助我们实现吗?

我想得到这样的东西:

Private Function GetTotalHours(ByVal year As String) As String
Dim time As String = String.Empty
Try
' Calculate here...

Catch ex As Exception

End Try
Return time
End Function

像这样使用它:

TextBox1.Text = GetTotalHours('2008')   ' Result will be = 8784
TextBox1.Text = GetTotalHours('2013') ' Result will be = 8760

最佳答案

你可以使用这个:

Public Function GetTotalHours(ByVal year As Integer) As Integer
Dim dtAux As New Date(year, 1, 1)
Dim ts As TimeSpan = dtAux.AddYears(1) - dtAux

Return CInt(ts.TotalHours)
End Function

关于vb.net - 如何使用 vb.net 获取一年中的总小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355502/

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