C# 常用方法
转换为UTF8编码
public static string UTF16To8(string str) { byte[] utf16Bytes = Encoding.Unicode.GetBytes(str); byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16Bytes); return Encoding.UTF8.GetString(utf8Bytes); }
DateTime转换为10位时间戳(单位:秒),参考:https://www.cnblogs.com/minotauros/p/10773258.html
/// <summary> /// DateTime转换为10位时间戳(单位:秒) /// </summary> private uint DateTimeToStamp(DateTime dateTime) { DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); return (uint)(dateTime.ToUniversalTime() - startTime).TotalSeconds; }