• 沙里软件

  • ShaliSoft.com [手机站]   办公桌收纳抽屉
  • 首页
  • 博文
  • 演示
  • 管理
  • JS版的时间比较函数DateDiff

    网络   2014/12/2 17:07:15
    //计算两个时间的间隔,并按指定格式显示
    //参数:格式,时间1,时间2
    //格式
    //y 年
    //q 季度
    //m 月
    //d 日
    //w 周
    //h 小时
    //n 分钟
    //s 秒
    //ms 毫秒
    function DateDiff(interval, date1, date2){
    var i={}, t=date1.getTime(), t2=date2.getTime();
    i['y']=date2.getFullYear()-date1.getFullYear();
    i['q']=i['y']*4+Math.floor(date2.getMonth()/4)-Math.floor(date1.getMonth()/4);
    i['m']=i['y']*12+date2.getMonth()-date1.getMonth();
    i['ms']=date2.getTime()-date1.getTime();
    i['w']=Math.floor((t2+345600000)/(604800000))-Math.floor((t+345600000)/(604800000));
    i['d']=Math.floor(t2/86400000)-Math.floor(t/86400000);
    i['h']=Math.floor(t2/3600000)-Math.floor(t/3600000);
    i['n']=Math.floor(t2/60000)-Math.floor(t/60000);
    i['s']=Math.floor(t2/1000)-Math.floor(t/1000);
    return i[interval]; 
    }


    阅读(1077) 分享(0)

    上一篇: js取小数点后两位方法大全
    下一篇: JS四舍五入的方法说明

  • 精彩推荐

    ◆ Win7的IIS7中ASP获得的系统日期格式为斜杠和去掉星期的解决办法
    ◆ 腾讯OA基础服务使用C# 开发的千万级应用
    ◆ 怎么做秒杀系统?秒杀系统设计
    ◆ 怎么设计比较安全的密码加密方法
    ◆ asp.net 用Stopwatch计算运行时间
    ◆ ASP.NET Eval四种绑定方式
    ◆ 安卓手机QQ新功能WiFi共享泄露用户隐私
    ◆ 我为什么不喜欢面向对象
    ◆ 老照片:马云、马化腾、李彦宏、刘强东、李开复,大佬们的罕见童年照
    ◆ 为什么刷单会被淘宝轻而易举的查到?
  • 用心做事 不能唯利是图

    • 吊儿
    • 用QQ联系我17905772
  • 搜索


  • 最新文章

    • 导出Excel 格式 mso-number-format
    • 服务器iis支持tls1.2,windows server 2008 r2 中IIS启用TLS 1.2(安装SSL后用TLS 1.2)
    • MySQL配置优化
    • EditPlus 添加文件比较工具winmerge
    • 滚动悬浮固定JS特效

  • 热门文章

    • php sso单点登录实现代码
    • 中国菜刀(China chopper) 最新黑客工具
    • redis.conf中文版(基于2.4)
    • 搜索引擎名单大全
    • php图片上传类,支持加水印,生成略缩图

  • 最新图库


  • 最新评论


  • 友情链接

  • 沙里软件

  • 最近访客

    Powered by ShaliSoft.com 豫ICP备13008529号

    免责声明:本站部分内容来源于互联网,转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,不为其版权负责,也不构成任何其他建议。如果发现侵犯版权,联系QQ17905772进行删除。