在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataSync.Utils { /// <summary> /// 时间工具类 /// </summary> public class DateTimeUtil { private static DateTime _dtStart = new DateTime(1970, 1, 1, 8, 0, 0); /// <summary> /// 获取时间戳 /// </summary> public static string GetTimeStamp(DateTime dateTime) { return Convert.ToInt64(dateTime.Subtract(_dtStart).TotalMilliseconds).ToString(); } /// <summary> /// 根据时间戳获取时间 /// </summary> public static DateTime TimeStampToDateTime(string timeStamp) { return _dtStart.AddMilliseconds(Convert.ToInt64(timeStamp)); } /// <summary> /// 根据时间戳获取时间 /// </summary> public static DateTime TimeStampToDateTime(long timeStamp) { if (timeStamp > 0) { return _dtStart.AddMilliseconds(timeStamp); } return DateTime.MinValue; } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论