zoukankan      html  css  js  c++  java
  • 时间计算规则

    mixin.js####

    export const TimeFiltering = {//时间格式化
        created(){
            Date.prototype.format = function(fmt) { 
                var o = { 
                   "M+" : this.getMonth()+1,                 //月份 
                   "d+" : this.getDate(),                    //日 
                   "h+" : this.getHours(),                   //小时 
                   "m+" : this.getMinutes(),                 //分 
                   "s+" : this.getSeconds(),                 //秒 
                   "q+" : Math.floor((this.getMonth()+3)/3), //季度 
                   "S"  : this.getMilliseconds()             //毫秒 
               }; 
               if(/(y+)/.test(fmt)) {
                       fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
               }
                for(var k in o) {
                   if(new RegExp("("+ k +")").test(fmt)){
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                    }
                }
               return fmt; 
           }
        }
    }
    

    .vue文件####

    <template>
        <div v-for="(item, index) in timeList" :key='index'>{{jisuan(item.time)}}</div>
    </template>
    <script>
        import {TimeFiltering} from '../mixins/mixins'
        export default {
            mixins: [TimeFiltering],
            data(){
                return {
                    timeList: [
                      {time: '2018-12-01 20:24:14'},
                      {time: '2018-12-31 20:24:14'},
                      {time: '2019-1-01 20:24:14'},
                      {time: '2019-1-02 20:24:14'},
                      {time: '2019-1-03 20:24:14'}
                    ]
                }
            },
            computed: {
              jisuan(){
                return function(time){
                  let nowTime = new Date().getTime()
                  let oldTime = new Date(time).getTime()
                  let oneDay = 24*60*60*1000
                  let twoDay = 2*24*60*60*1000
                  let oneWeek = 7*24*60*60*1000
                  let nowDay = new Date(time).getDay()
                  if (nowTime - oldTime < oneDay){
                    return new Date(time).format("hh:mm")
                  }else if( nowTime - oldTime < twoDay){
                    return '昨天'
                  } else if ( nowTime - oldTime < oneWeek ){
                    switch (nowDay) {
                      case 0:
                        return '星期天';
                      case 1:
                        return '星期一';
                      case 2:
                        return '星期二';
                      case 3:
                        return '星期三';
                      case 4:
                        return '星期四';
                      case 5:
                        return '星期五';
                      case 6:
                        return '星期六';
                    }
                  } else {
                    return new Date(time).format("yyyy-MM-dd hh:mm:ss")
                  }
                }
              }
            }
        }
    </script>
    
  • 相关阅读:
    ab访问并发测试简要步骤
    使用sysbench 进行msyql oltp压力测试
    pycham database查看db.sqlites文件 无内容解决方法
    mysql 批量修改字段方法
    mysql row日志格式下 查看binlog sql语句
    shiro自定义过滤器
    shiro【filter】
    js 中时间格式化的几种方法
    @Value("#{}")与@Value("${}")的区别
    IDEA 代码格式化,快捷键
  • 原文地址:https://www.cnblogs.com/yzyh/p/10217706.html
Copyright © 2011-2022 走看看