我如何才能将文件创建时间添加到我的 .txt 名称中?
How would I get it to add the File Creation time to my .txt name?
我正在为我的 DataGridView 创建多个 .txt 文件,我想为它们添加创建日期。
*****编辑*****
我已将我的代码更改为以下内容以查看它是否会输出时间戳:
private void button2_Click(object sender, EventArgs e)
{
DateTime timenow = new DateTime();
DateTime.Now.ToString("yyyyddhh");
Console.WriteLine(timenow.ToString());
string LPath = Path.Combine(path, Path.GetRandomFileName() + ".txt");
using (StreamWriter objWriter = new StreamWriter(LPath, true))
{
string LContent = textName.Text + "," + textVehicle.Text + "," + textDurationH.Text + " " + textDurationM.Text + "," + textFreight.Text + "," + textWeight.Text + "," + textIncome.Text + "," + LPath;
objWriter.Write(LContent);
infoTabelle.Rows.Add(LContent.Split(','));
objWriter.WriteLine();
}
replace();
}
但它只输出 01.01.0001 00:00:00。
我需要做什么? :/
我尝试过使用各种 DateTime 命令,但 none 似乎对我有用。感谢您的帮助!
尝试
DateTime timenow = DateTime.Now;
而不是
DateTime timenow = new DateTime();
然后将其添加到您的文件名字符串中。
我正在为我的 DataGridView 创建多个 .txt 文件,我想为它们添加创建日期。 *****编辑***** 我已将我的代码更改为以下内容以查看它是否会输出时间戳:
private void button2_Click(object sender, EventArgs e)
{
DateTime timenow = new DateTime();
DateTime.Now.ToString("yyyyddhh");
Console.WriteLine(timenow.ToString());
string LPath = Path.Combine(path, Path.GetRandomFileName() + ".txt");
using (StreamWriter objWriter = new StreamWriter(LPath, true))
{
string LContent = textName.Text + "," + textVehicle.Text + "," + textDurationH.Text + " " + textDurationM.Text + "," + textFreight.Text + "," + textWeight.Text + "," + textIncome.Text + "," + LPath;
objWriter.Write(LContent);
infoTabelle.Rows.Add(LContent.Split(','));
objWriter.WriteLine();
}
replace();
}
但它只输出 01.01.0001 00:00:00。 我需要做什么? :/
我尝试过使用各种 DateTime 命令,但 none 似乎对我有用。感谢您的帮助!
尝试
DateTime timenow = DateTime.Now;
而不是
DateTime timenow = new DateTime();
然后将其添加到您的文件名字符串中。