function formatDate(date, pattern) {
if(typeof pattern == 'undefined'){
pattern = 'yyyy-MM-dd';
}
var str = '';
if (date instanceof Date) {
console.log('yes date')
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month <= 9) {
month = '0' + month;
}
var day = date.getDate();
if (day <= 9) {
day = '0' + day;
}
str = pattern.replace('yyyy', year).replace('MM', month).replace('dd', day);
} else {
console.log('no date')
}
return str;
}