• js时间戳转化时间格式


    // 判断是否前面补0
        add0 (m) {
          return m < 10 ? '0' + m : m
        },
        // 时间转化
        timeFormat (timestamp) {
        // timestamp是整数,否则要parseInt转换,不会出现少个0的情况
          var time = new Date(timestamp)
          // var year = time.getFullYear()
          // var month = time.getMonth() + 1
          // var date = time.getDate()
          var hours = time.getHours()
          var minutes = time.getMinutes()
          var seconds = time.getSeconds()
          // return year + '-' + this.add0(month) + '-' + this.add0(date) + ' ' + this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
          return this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
        },

    // 时间戳转化为时间
                formatDateTime:function (timeStamp) { 
                    if(timeStamp != null&&timeStamp != 0){
                        var date = new Date();
                        date.setTime(timeStamp * 1000);
                        var y = date.getFullYear();    
                        var m = date.getMonth() + 1;    
                        m = m < 10 ? ('0' + m) : m;    
                        var d = date.getDate();    
                        d = d < 10 ? ('0' + d) : d;    
                        var h = date.getHours();  
                        h = h < 10 ? ('0' + h) : h;  
                        var minute = date.getMinutes();  
                        var second = date.getSeconds();  
                        minute = minute < 10 ? ('0' + minute) : minute;    
                        second = second < 10 ? ('0' + second) : second;   
                        // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;  
                        return y + '-' + m + '-' + d;  
                    }else{
                        return ''
                    }
                }
    
    
    
     

     这只是为了方便,纯属记录!

    // 时间戳转化为时间
    formatDateTime:function (timeStamp) {
    if(timeStamp != null&&timeStamp != 0){
    var date = new Date();
    date.setTime(timeStamp * 1000);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d;
    }else{
    return ''
    }
    }
  • 相关阅读:
    50.Ext_数字输入框_Ext.form.NumberField
    49.Ext.form.TextField()基本用法
    48.EXt.Data.JsonReader()
    47. Ext.form.Field.prototype.msgTarget
    46. Ext中namespace的作用(转)
    45. ExtJS ComboBox 下拉列表详细用法
    44. Ext信息提示对话框
    43. ExtJs控件属性配置详细
    42.extjs Combobox动态加载数据问题,mode:local 还是remote
    堆叠顺序
  • 原文地址:https://www.cnblogs.com/zeng2210/p/8906247.html
Copyright © 2020-2023  润新知