C#时间格式转换为时间戳互转

时间:2024-11-02 12:34:37
 /// <summary>
        /// 将 DateTime时间格式转换为Unix时间戳格式
        /// </summary>
        /// <param name="time">时间</param>
        /// <returns>long</returns>
        public static long ConvertDateTimeToInt(DateTime time)
        {
            System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(, , , , , , ));
            ;   //除10000调整为13位
            return TimeStamp;
        }

        /// <summary>
        /// 将Unix时间戳格式 转换为DateTime时间格式
        /// </summary>
        /// <param name="time">时间</param>
        /// <returns>long</returns>
        public static DateTime ConvertDateTimeToInt(long time)
        {
            System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(, , , , , , ));
            DateTime dateTime = Time.AddMilliseconds(time);
            return dateTime;
        }