码迷,mamicode.com
首页 > 其他好文 > 详细

活动的创建时间

时间:2015-06-16 16:14:11      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

注意问题:

时间格式返回是秒还毫秒;

 //计算创建时间与当前时间的距离
     function getTimeSpan(origTime) {
      if (origTime < 10000000000)
             origTime = origTime * 1000    //秒是10位,如果是小于11位则说明不是毫秒,要加三位变成毫秒

         var d = new Date();
         var span = d.getTime() - origTime;
         var days = Math.floor(span / (24 * 3600 * 1000));
         if (days > 0) {
             var n = new Date(origTime);
             var result = n.getFullYear() + "-" + (n.getMonth() + 1) + "-" + n.getDate();
             return result;
         }
         else {
             var leave = Math.floor(span % (24 * 3600 * 1000));
             hours = Math.floor(leave / (3600 * 1000));
             if (hours > 0) {
                 return hours + "小时前";
             }
             else {
                 var minutes = Math.floor(leave % (3600 * 1000));
                 minutes = Math.floor(minutes / (60 * 1000));
                 if (minutes > 0) {
                     return minutes + "分钟前";
                 }
                 else {
                     return "刚刚";
                 }
             }
         }
     }
      //计算当前时间到结束时间的距离
     function timeCountDown(origTime) {

      if (origTime < 10000000000)
             origTime = origTime * 1000

         var d = new Date();
         var span = origTime - d.getTime();
         if (span<=0) {
             return "已结束";
         }
         var days = Math.floor(span / (24 * 3600 * 1000));
         if (days > 0) {
             return "还剩" + days + "天结束";
         }
         else {
             var leave = Math.floor(span % (24 * 3600 * 1000));
             hours = Math.floor(leave / (3600 * 1000));
             if (hours > 0) {
                 return "还剩" + hours + "小时结束";
             }
             else {
                 var minutes = Math.floor(leave % (3600 * 1000));
                 minutes = Math.floor(minutes / (60 * 1000));
                 if (minutes > 0) {
                     return "还剩" + minutes + "分钟结束";
                 }
                 else {
                     return "即将结束";
                 }
             }
         }
     }

      //long型时间转换为格式化的日期时间
     function ConvertLongToDate(origTime)
     {
      if (origTime < 10000000000)
             origTime = origTime * 1000

         var d = new Date();
         var span = d.getTime() - origTime;
         var days = Math.floor(span / (24 * 3600 * 1000));
         var n = new Date(origTime);
         if (days > 0) {             
             var result = n.getFullYear() + "-" + (n.getMonth() + 1) + "-" + n.getDate();
             return result;
         }
         else {
             var result = n.getHours() + ":" + n.getMinutes();
             return result;
         }
     }

活动的创建时间

标签:

原文地址:http://www.cnblogs.com/wangjiaojiao/p/4580791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!