using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HH.YiDaSyncNC.Helper
{
    class UnixTimeHelper
    {
        public static DateTime ConvertMillisecondsToDateTime(long milliseconds)
        {
            // 毫秒数需要转换为秒
            double seconds = milliseconds / 1000.0;
            // Unix时间起始时间1970-01-01 00:00:00
            DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            // 将秒数转换为TimeSpan，然后添加到Unix起始时间
            TimeSpan timeSpan = TimeSpan.FromSeconds(seconds);
            // 返回结果的UTC时间
            return unixStartTime.Add(timeSpan).ToLocalTime();
        }

        public static long ConvertToMilliseconds(DateTime dateTime)
        {
            DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan timeSpan = dateTime.ToUniversalTime() - epoch;
            return (long)timeSpan.TotalMilliseconds;
        }
    }
}
