我有这样的Vb.net代码:
Dim requestddate As DateTime = DateTime.Now
Dim rdate As Date = requestddate.Date
Dim rtime As TimeSpan = requestddate.TimeOfDay
在rtime
varibale中,我想只获得时间:03:15:10
(小时,分钟,秒)。
但现在我的rtime
值为03:15:10.7929313
。
答案 0 :(得分:1)
TimeSpan
包含all properties,例如,无法删除毫秒。如果您希望将此TimeSpan
显示为String
,则可以使用ToString
:
requestddate.TimeOfDay.ToString("hh\:mm\:ss"))
答案 1 :(得分:0)
您可以使用一个事实,TimeSpan(Int32, Int32, Int32)
可能需要60
seconds
作为Dim rtime As New TimeSpan(0, 0, CInt(requestddate.TimeOfDay.TotalSeconds))
参数值:
{{1}}
答案 2 :(得分:0)
Dim requestddate As DateTime = DateTime.Now
Dim rdate As Date = requestddate.Date
Dim rtime As TimeSpan = requestddate.TimeOfDay
Dim t As String = rtime.Hours & ":" & rtime.Minutes & ":" & rtime.Seconds