C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: You can see in this example that the year, month, and day were correctly parsed.
However: The time was left at zero (equivalent to 12 AM), because none was specified. When you don't specify a time it is left at 12 AM.
VB.NET program that uses DateTime.Parse function
Module Module1
Sub Main()
Dim value As String = "2000-02-02"
Dim time As DateTime = DateTime.Parse(value)
Console.WriteLine(time)
End Sub
End Module
Output
2/2/2000 12:00:00 AM
Note: This function appeared to work correctly on all of the input strings, which means it is fairly flexible.
VB.NET program that uses DateTime.Parse in examples
Module Module1
Sub Main()
' Simple slash format
Dim time As DateTime = DateTime.Parse("1/1/2000")
Console.WriteLine(time)
' HTTP header
time = DateTime.Parse("Fri, 27 Feb 2009 03:11:21 GMT")
Console.WriteLine(time)
' From w3.org
time = DateTime.Parse("2009/02/26 18:37:58")
Console.WriteLine(time)
' From nytimes.com
time = DateTime.Parse("Thursday, February 26, 2009")
Console.WriteLine(time)
' From dotnetCodex.com
time = DateTime.Parse("February 26, 2009")
Console.WriteLine(time)
' From ISO Standard 8601 for Dates
time = DateTime.Parse("2002-02-10")
Console.WriteLine(time)
' From Windows file system Created/Modified
time = DateTime.Parse("2/21/2009 10:35 PM")
Console.WriteLine(time)
' From Windows Date and Time panel
time = DateTime.Parse("8:04:00 PM")
Console.WriteLine(time)
End Sub
End Module
Output
1/1/2000 12:00:00 AM
2/26/2009 8:11:21 PM
2/26/2009 6:37:58 PM
2/26/2009 12:00:00 AM
2/26/2009 12:00:00 AM
2/10/2002 12:00:00 AM
2/21/2009 10:35:00 PM
6/2/2010 8:04:00 PM
And: The string type is more useful for input and output such as writing to files.