UTC转本地时间(时间戳)

        private static DateTime StampToDateTime(string time)
        {

            time = time.Substring(0, 10);
            double timestamp = Convert.ToInt64(time);
            System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
            dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();
            return dateTime;
        }
            double dt = 1578209579;
            Console.WriteLine(StampToDateTime(dt.ToString()).ToString("yyyy.MM.dd HH:mm:ss"));//tips:(HH24小时  hh12小时)

任意时间转换问题:

		public static int ConvertDateTimeInt(System.DateTime time)
        {
            double intResult = 0;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            intResult = (time - startTime).TotalSeconds;
            return (int)intResult;
        }
        public static DateTime ConvertIntDatetime(double utc)

        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            startTime = startTime.AddSeconds(utc);
            startTime = startTime.AddHours(int.Parse(DateTime.Now.ToString("%z")));//转化为北京时间(北京时间=UTC时间+8小时 )            
            return startTime;
        }
        //调用方法
        // DateTime utcNow = DateTime.Now.ToUniversalTime();
        // double utc= ConvertDateTimeInt(utcNow);
        // DateTime dtime = ConvertIntDatetime(utc);

你可能感兴趣的:(Unity_c#_ugui,c#)