我希望日期格式为文件夹名称(27-07-2010)..如何命名?我想把它作为我的子目录
答案 0 :(得分:6)
您可以使用System.IO.Directory.CreateDirectory
创建目录,并可以使用日期格式字符串指定名称:
var dirName = string.Format("{0:dd-MM-yyyy}", DateTime.Now);
System.IO.Directory.CreateDirectory(dirName);
答案 1 :(得分:3)
试试这个:
DateTime dateTime;
dateTime.ToString("dd-MM-yyyy");
<强>更新强>
// The date you want for your folder.
// Could be: DateTime.Now
DateTime dateTime;
// The parent folder you want to create a subfolder in
// Could be: AppDomain.CurrentDomain.BaseDirectory for current dir
string parentFolder;
Directory.CreateDirectory(Path.Combine(parentFolder, dateTime.ToString("dd-MM-yyyy")));