日期:2014-05-19  浏览次数:20491 次

如何按照当前时间生成一个不重复的文件名
如题。。

------解决方案--------------------
DateTime dataTime = DateTime.Now;
string name = dataTime.Year.ToString();
if (dataTime.Month < 10)
{
name += "0 " + dataTime.Month;
}
else
{
name += dataTime.Month;
}
if (dataTime.Day < 10)
{
name += "0 " + dataTime.Day;
}
else
{
name += dataTime.Day;
}
if (dataTime.Hour < 10)
{
name += "0 " + dataTime.Hour;
}
else
{
name += dataTime.Hour;
}
if (dataTime.Minute < 10)
{
name += "0 " + dataTime.Minute;
}
else
{
name += dataTime.Minute;
}
if (dataTime.Second < 10)
{
name += "0 " + dataTime.Second;
}
else
{
name += dataTime.Second;
}
if (dataTime.Millisecond < 10)
{
name += "00 " + dataTime.Millisecond;
}
else if (dataTime.Millisecond > = 10 && dataTime.Millisecond < 100)
{
name += "0 " + dataTime.Millisecond;
}
else
{
name += dataTime.Millisecond;
}