Files
Web_PMSApi_Server_V1_Prod/BLWWS/Common.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2025-11-20 15:56:30 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace BLWWS
{
public class Common
{
public static string MD5Encrypt(string str)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] hashedDataBytes;
hashedDataBytes = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str));
StringBuilder tmp = new StringBuilder();
foreach (byte i in hashedDataBytes)
{
tmp.Append(i.ToString("x2"));
}
return tmp.ToString();
}
public static long GetCurrentTimeStamp(DateTime dt)
{
TimeSpan ts = dt - new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Local);
long current_timestamp = Convert.ToInt64(ts.TotalSeconds);
return current_timestamp;
}
public static DateTime GetCurrentDateTime(long timestampseconds)
{
DateTime epoch = new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Local);
DateTime utcTime = epoch.AddSeconds(timestampseconds);
return utcTime;
}
}
}