//获取系统当前时间
var nowdate = new Date()
var y = nowdate.getFullYear()
var m = (nowdate.getMonth()+1).toString().padStart(2,'0')
var d = nowdate.getDate().toString().padStart(2,'0')
var currentTime = y+'-'+m+'-'+d
that.date1=currentTime
that.date3=currentTime
//获取系统前一个月的时间
nowdate.setMonth(nowdate.getMonth()-1)
var y = nowdate.getFullYear()
var m = (nowdate.getMonth()+1).toString().padStart(2,'0')
var d = nowdate.getDate().toString().padStart(2,'0')
var preMonth = y+'-'+m+'-'+d
that.date=preMonth
that.date2=preMonth
适用于时间戳转换日期的时候顺便补0
var change = new Date(that.dataList[i][0] * 1000)
var Y = change.getFullYear() + "-"
var M = (change.getMonth() + 1 <10 ? "0" + (change.getMonth() + 1) : change.getMonth() + 1) + "-"
var D= (change.getDate() <10 ? "0" + (change.getDate()) : change.getDate()) + " "
var h= (change.getHours() <10 ? "0" + (change.getHours()) : change.getHours()) + ":"
var m= (change.getMinutes() <10 ? "0" + (change.getMinutes()) : change.getMinutes()) + ":"
var s= (change.getSeconds() <10 ? "0" + (change.getSeconds()) : change.getSeconds())
var newDate = Y + M + D + h + m + s
function formatnumber(value, num){
var a, b, c, i
a = value.toString()
b = a.indexOf(".")
c = a.length
if (num == 0) {
if (b != -1) {
a = a.substring(0, b)
}
} else {//如果没有小数点
if (b == -1) {
a = a + "."
for (i = 1 i <= num i++) {
a = a + "0"
}
} else {//有小数点,超出位数自动截取,否则补0
a = a.substring(0, b + num + 1)
for (i = c i <= b + num i++) {
a = a + "0"
}
}
}
return a
}
alert(formatnumber(3.1,4))//使用方法,第一个参数是你要转化的小数,第二个是位数
1)在input失去焦点的func里面操作,2)检查文本的长度:
if 文本长度离目标长度相差n的话
then input的文本 = n*0 + 原文本
即可。