首页 > 代码库 > 文件名称 (年4+月2+日2+时2+分2+秒2+毫秒3+8位随机数)

文件名称 (年4+月2+日2+时2+分2+秒2+毫秒3+8位随机数)

 public  string GeFileName(string type)
    {
        //年4+月2+日2+时2+分2+秒2+毫秒3+8位随机数
        string year = DateTime.Now.Year.ToString();
        string month = DateTime.Now.Month.ToString();
        if (month.Length < 2) { month = "0" + month; }
        string day = DateTime.Now.Day.ToString();
        if (day.Length < 2) { day = "0" + day; }
        string hour = DateTime.Now.Hour.ToString();
        if (hour.Length < 2) { hour = "0" + hour; }
        string minute = DateTime.Now.Minute.ToString();
        if (minute.Length < 2) { minute = "0" + minute; }
        string second = DateTime.Now.Second.ToString();
        if (second.Length < 2) { second = "0" + second; }
        string millisecond = DateTime.Now.Millisecond.ToString("000");
        //8位随机数
        Random rad = new Random();
        int value = http://www.mamicode.com/rad.Next(10000000, 100000000);
        string fileName = year + month + day + hour + minute +second+ millisecond + value.ToString()+type;
        return fileName;
    }