js 格式化时间
1.日期格式转为日期标准字符串:2015-01-10
var formatDate = function (date) {
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;
return y + '-' + m + '-' + d;
}
2.easyui中格式化:1996-01-10
formatter : function(value, rec,
index) {
return new Date().format('yyyy-MM-dd', value);
}
4.返回
//返回时间戳转Strig
function time(value) {
var date = new Date(value);
var Y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
if (m < 10) {
m = '0' + m;
}
if (d < 10) {
d = '0' + d;
}
var t = Y+'-'+m+'-'+d;
return t;
}
5.格式化时间戳
function format(timestamp) {
//timestamp是整数,否则要parseInt转换
var time = new Date(timestamp);
var y = time.getFullYear();
var m = time.getMonth() + 1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y + '-' + paddingZero(m) + '-' + paddingZero(d) + ' '
+ paddingZero(h) + ':' + paddingZero(mm) + ':' + paddingZero(s);
}