Vb.net - 日期:如何获得当天的开始时间和结束时间

时间:2013-11-05 12:18:03

标签: vb.net

我们如何在vb.net中完成此任务:获取白天时间和一天结束时间

例如

Start DateTime: 05-Nov-2013 00:00:00
End DateTime: 05-Nov-2013 23:59:99

Regars

3 个答案:

答案 0 :(得分:1)

Dim start As DateTime = yourDate.Date
Dim endTime As DateTime = yourDate.Date.AddDays(1).AddSeconds(-1)

答案 1 :(得分:1)

您可以将TimeSpan添加到日期值,如下所示:

Dim dateValue As DateTime = DateTime.Now

Dim startTime As DateTime = dateValue.Date + New TimeSpan(0, 0, 0) 'timespan addition not actually needed here
Dim endTime As DateTime = dateValue.Date + New TimeSpan(23, 59, 59)

答案 2 :(得分:0)

我的$ .02

    Dim someDate As DateTime = DateTime.Now
    Dim StartDateTime As DateTime = someDate.Date
    'last measurable instant for a given date
    Dim EndDateTime As DateTime = someDate.Date.Add(New TimeSpan(TimeSpan.TicksPerDay - 1))