var dateTime = {
getDateByFormat: function (dateStr) {
dateStr = dateStr.replace('-', '/');
return new Date(Date.parse(dateStr));
},
dateFormat: function (date, formatStr) {
var date = new Date(date);
var opt = {
'yyyy': date.getFullYear(),
'MM': addZero(date.getMonth() + 1),
'M': date.getMonth() + 1,
'dd': addZero(date.getDate()),
'd': date.getDate(),
'HH': addZero(date.getHours()),
'H': date.getHours(),
'mm': addZero(date.getMinutes()),
'm': date.getMinutes(),
'ss': addZero(date.getSeconds()),
's': date.getSeconds()
};
function addZero(value) {
return value < 10 ? '0' + value : value;
}
for (var k in opt) {
formatStr = formatStr.replace(k, opt[k]);
}
return formatStr;
},
formatPattern: 'yyyy-MM-dd HH:mm:ss'
}