123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Security.Cryptography;
- using System.Text;
- public class Util
- {
- /// <summary>
- /// 转换方法
- /// </summary>
- /// <param name="size">字节值</param>
- /// <returns></returns>
- public static string HumanReadableFilesize(double size)
- {
- String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB" };
- double mod = 1024.0;
- int i = 0;
- while (size >= mod)
- {
- size /= mod;
- i++;
- }
- int littleNum = 0;//取几位小数
- if (i == 0 || i == 1)
- littleNum = 0;
- else
- littleNum = 2;
- return Math.Round(size, littleNum) + units[i];
- }
- /// <summary>
- /// MD5Encrypt
- /// </summary>
- /// <param name="str"></param>
- /// <returns></returns>
- public static string MD5Encrypt(string str)
- {
- MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
- byte[] bytes = Encoding.ASCII.GetBytes(str);
- byte[] encoded = md5.ComputeHash(bytes);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 10; i++)
- {
- sb.Append(encoded[i].ToString("x2"));
- }
- string str1 = sb.ToString();
- str1 = str1.Substring(0, 10);
- return str1;
- }
- public static string changTime(double size)
- {
- DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- DateTime dt = startTime.AddSeconds(size);
- //string t = dt.ToString("yyyy/MM/dd HH:mm:ss");
- string t = dt.ToString("yyyy/MM/dd");
- return t;
- }
- }
|