I am writing files to my harddrive,The filename is build like this:
String.Format("{0:yyyy-MM-dd_hh-mm-ss}.txt", DateTime.Now)
So the filename is "2010-09-20_09-47-04.txt" for example. Now I want to show those filenames in a dropdown, but with another format. The format should be dd.MM.yyyy HH:mm:ss. How can I do that, or is there a better approach?
Thanks :)
I tried this on console and it did the job.
Imports System.Globalization
Module Module1
Sub Main()
Dim enUS As New CultureInfo("en-US")
Dim d As String = Format(DateTime.Now, "yyyy-MM-dd_hh-mm-ss")
Dim da As Date = DateTime.ParseExact(d, "yyyy-MM-dd_hh-mm-ss", enUS)
Console.WriteLine("Date from filename: {0}", d)
Console.WriteLine("Date formated as date: {0}", Format(da, "dd.MM.yyyy HH:mm:ss"))
End Sub
End Module
Hope it helps.
You can use DateTime.ParseExact with the same format you use to build name to parse the file name into DateTime object and than convert it to the desired format with ToString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With