2

VB.Net を使用して、1 年間の総時間数を取得したいと考えています。それを達成するのに役立つ方法や機能はありますか?

次のようなものを取得したい:

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
4

1 に答える 1

5

これを使用できます:

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
于 2013-01-16T09:59:37.130 に答える