zoukankan      html  css  js  c++  java
  • 活动的创建时间

    注意问题:

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

     //计算创建时间与当前时间的距离
         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;
             }
         }

  • 相关阅读:
    uva 11995 I Can Guess the Data Structure!
    poj 1981 Circle and Points
    hdoj 2149 Public Sale
    hdoj 2188 悼念512汶川大地震遇难同胞——选拔志愿者
    hdoj 1846 Brave Game
    vue 细节注意
    meta标签设置不缓存
    -webkit-overflow-scrolling
    ios上表单默认样式
    vue-cli项目上传到github预览问题
  • 原文地址:https://www.cnblogs.com/wangjiaojiao/p/4580791.html
Copyright © 2011-2022 走看看