我正在为我的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命令但似乎没有一个对我有效。任何帮助表示赞赏!
答案 0 :(得分:0)
尝试
DateTime timenow = DateTime.Now;
而不是
DateTime timenow = new DateTime();
然后将其添加到您的文件名字符串。