[英]How to get total number of hours in a year using vb.net?
我想使用 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.