我想要今天的日期。使用Now(),我得到了date和time,但我只需要date。如何获得它?谢谢弗尔坎
发布于 2011-02-01 17:58:15
使用。一些额外的注意事项:
System.DateTime对象。也就是说,在返回值中仍然有时间部分,但将其留空(全为零)。在比较日期时,记住这一点很重要。如果你想比较两个日期,并且你已经通过DateTime.Today获取了一个日期,而通过DateTime.Now获取了另一个日期,那么这两个日期将不相等--这正是因为一个日期设置了时间,而另一个没有。
Date关键字相当于System.DateTime类型。所以你可以这样写:Date.Today
附言:我刚刚想到写Date.Today可能是个好主意,但是DateTime.Now,为了更明确地说明前者只返回日期部分,而后者同时返回日期和时间部分。
发布于 2011-02-01 17:47:11
只对当前日期尝试DateTime.Today方法。
这将返回一个DateTime对象,就像DateTime.Now一样,但它的时间部分始终设置为0。
发布于 2011-02-01 17:48:14
Imports System
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim currentTime as System.DateTime = System.DateTime.Now
Console.WriteLine("currentTime Year :" & currentTime.Year)
Console.WriteLine("currentTime Month:" & currentTime.Month)
Console.WriteLine("currentTime Date:" & currentTime.Date)
Console.WriteLine("currentTime Hour:" & currentTime.Hour)
Console.WriteLine("currentTime Minute:" & currentTime.Minute)
Console.WriteLine("currentTime Second:" & currentTime.Second)
End Sub
End Classhttps://stackoverflow.com/questions/4861021
复制相似问题