开发者

Output Date Without Slashes

开发者 https://www.devze.com 2023-01-24 10:07 出处:网络
I need to create a file that has t开发者_如何学JAVAoday\'s date in the file name.How can I get the date just as 20111110 and no slashes?DateTime.Now.ToString(\"yyyyMMdd\")

I need to create a file that has t开发者_如何学JAVAoday's date in the file name. How can I get the date just as 20111110 and no slashes?


DateTime.Now.ToString("yyyyMMdd")

Also, you may not be be aware of System.IO.Path.Combine. It makes building paths a little cleaner and more foolproof.


Simply use a custom datetime format string.

myDate.ToString("yyyyMMdd");


how about something like this:

System.IO.FileInfo file = new System.IO.FileInfo(File1.PostedFile.FileName);
string fname = file.Name.Remove((file.Name.Length - file.Extension.Length));
fname = fname + Now.ToString("_MMddyyyy_HHmmss") + file.Extension;

This creates the filename with the embedded datetime. Then you can prepend you folder path and pass it to SaveAs.


Try this:

  DateTime d = DateTime.Now;
  string s = d.ToString("yyyyMMdd");
0

精彩评论

暂无评论...
验证码 换一张
取 消