DateTime类型long类型转换

    /// <summary>
    /// 将DateTime类型转换为long类型
    /// </summary>
    /// <param name="dt">时间</param>
    /// <returns></returns>
    public static long ConvertDataTimeLong(DateTime dt)
    {
        //dateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000
        DateTime dtBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        TimeSpan toNow = dt.ToUniversalTime().Subtract(dtBase);
        long timeStamp = toNow.Ticks / 10000;
        return timeStamp;
    }
    /// <summary>
    /// 将long类型转换为DateTime类型
    /// </summary>
    /// <param name="timeStamp">时间戳</param>
    /// <returns></returns>
    public static DateTime ConvertLongtoDataTime(long timeStamp)
    {
        DateTime dtBase = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(timeStamp);
        return dtBase;
    }`
上一篇:数据库mysql之视图的创建


下一篇:随机生成10000个字符串