时间转换为Unix时间戳

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

namespace Common
{
    public class DateUtils
    {
        /// <summary>
        /// 时间转换为Unix时间戳
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static int DateConvertToInt(DateTime date)
        {
            DateTime newDate = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
            return (int)(date - newDate).TotalSeconds;
        }
    }
}

 

posted @ 2016-12-29 15:14  码到世界末日  阅读(362)  评论(0编辑  收藏  举报