AxibugEmuOnline/AxibugEmuOnline.Server/Common/Helper.cs

39 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-09-20 18:27:13 +08:00
using System.Security.Cryptography;
using System.Text;
namespace AxibugEmuOnline.Server.Common
2024-06-28 17:43:55 +08:00
{
public static class Helper
{
public static long GetNowTimeStamp()
{
return GetTimeStamp(DateTime.Now);
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static long GetTimeStamp(DateTime dt)
{
TimeSpan ts = dt - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds);
}
2024-09-20 18:27:13 +08:00
public static string FileMD5Hash(string filePath)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filePath))
{
var hash = md5.ComputeHash(stream);
var sb = new StringBuilder(hash.Length * 2);
foreach (var b in hash)
sb.AppendFormat("{0:x2}", b);
return sb.ToString();
}
}
}
2024-06-28 17:43:55 +08:00
}
}