吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3334|回复: 0
收起左侧

[其他转载] .net MYSQL时间转换的2个方法

 关闭 [复制链接]
√楓殺 发表于 2010-9-2 10:59
我前段时间写的2个方法   觉得还不错 共享给大家

 
/// <summary>
        /// 将系统时间转换成UNIX时间戳(把系统时间转换成Mysql时间)
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public long GetNowPHPTick(System.DateTime time)
        {
            double intResult = 0;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            intResult = (time - startTime).TotalSeconds;
            return (long)(intResult - 8 * 60 * 60);
        }
        /// <summary>
        /// 将UNIX时间戳转换成系统时间(Mysql取出来的转换成系统时间)
        /// </summary>
        /// <param name="dateDouble"></param>
        /// <returns></returns>
        public DateTime GetDateTime(long dateDouble)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(dateDouble + "0000000");
            TimeSpan toNow = new TimeSpan(lTime);
            return dtStart.Add(toNow);
        }

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 22:56

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表