using System;
using System.Security.Cryptography;
using System.Text;
public class Util
{
///
/// 转换方法
///
/// 字节值
///
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];
}
///
/// MD5Encrypt
///
///
///
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;
}
}