getDateDiff:function (dateTimeStamp) {
var minute = 60
var hour = minute * 60
var day = hour * 24
var halfamonth = day * 15
var month = day * 30
var now = Date.parse(new Date())/1000 //有些特殊 不能使用 new Date()
var diffValue = now - dateTimeStamp
if(diffValue <0){return}
var monthC =diffValue/month
var weekC =diffValue/(7*day)
var dayC =diffValue/day
var hourC =diffValue/hour
var minC =diffValue/minute
var result = ''
if(monthC >= 1){
result="" + parseInt(monthC) + "月前"
}
else if(weekC>=1){
result="" + parseInt(weekC) + "周前"
}
else if(dayC>=1){
result=""+ parseInt(dayC) +"天前"
}
else if(hourC>=1){
result=""+ parseInt(hourC) +"小时前"
}
else if(minC>=1){
result=""+ parseInt(minC) +"分钟前"
}else{
result="刚刚"
}
return result
}//时间戳转化为几天前,几小时前,几分钟前
Date.prototype.Format=function(formatStr){return formatStr.replace(/yyyy|YYYY/,this.getFullYear()).replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100)).replace(/MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString():'0' + (this.getMonth()+1)).replace(/M/g,(this.getMonth()+1)).replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate()).replace(/d|D/g,this.getDate()).replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours()).replace(/h|H/g,this.getHours()).replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes()).replace(/m/g,this.getMinutes()).replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds()).replace(/s|S/g,this.getSeconds()).replace(/w|W/g,['日','一','二','三','四','五','六'][this.getDay()])}var timer=Date.parse("12/30/2017 12:00:00")
alert( new Date(timer).Format("YYYY年MM月DD") ) //2017年12月30
alert( new Date(timer).Format("YYYY年MM月DD日 HH时mm分SS秒 星期W") ) //2017年12月30日 12时00分00秒 星期六
Date.parseDate是将字符串转为Date:Date.parseDate('2013-01','Y-m') //结果Mon Jan 28 00:00:00 UTC+0800 2013(Date)
Ext.util.Format.date()是将日期类型转换为字符串
Ext.util.Format.date('2013/1/28 0:00:00','Y-m') //结果是"2013-01"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)