使用timepan只能获得从datetime开始没有毫秒的时间

时间:2013-07-16 11:22:58

标签: vb.net

我有这样的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

3 个答案:

答案 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