使用日期时间为文件名和事后分析的文件名? [英] Using a datetime as filename and parse the filename afterwards?
本文介绍了使用日期时间为文件名和事后分析的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写文件到我的硬盘,文件名是建立这样的:
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)
所以,文件名是2010-09-20_09-47-04.txt为例。现在,我要显示在下拉的文件名,但有另一种格式。格式应该是DD.MM.YYYY HH:MM:SS。我如何能做到这一点,或者是有一个更好的办法
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?
感谢:)
推荐答案
我尝试这个控制台上,它做的工作。
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
希望它帮助。
这篇关于使用日期时间为文件名和事后分析的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文