C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Step 1: When you access DateTime.Now, the current time is computed. This is stored in a Structure.
Step 2: The Sleep call causes 10 seconds to pass. So the current time has changed.
SleepStep 3: The second DateTime returned by Now is 10 seconds later. The value returned by Now keeps changing.
VB.NET program that uses DateTime.Now
Module Module1
Sub Main()
' Step 1: load now into local variable.
Dim now As DateTime = DateTime.Now
Console.WriteLine(now)
' Step 2: sleep 10 seconds.
Threading.Thread.Sleep(10000)
' Step 3: use property again.
Console.WriteLine(DateTime.Now)
End Sub
End Module
Output
2/3/2020 4:25:30 AM
2/3/2020 4:25:40 AM
So: We can use Today instead of Now when we do not want the time part of the DateTime structure.
VB.NET program that uses DateTime.Today
Module Module1
Sub Main()
Console.WriteLine("NOW: {0}", DateTime.Now)
Console.WriteLine("TODAY: {0}", DateTime.Today)
End Sub
End Module
Output
NOW: 2/3/2020 4:33:38 AM
TODAY: 2/3/2020 12:00:00 AM