获取当前日期(年-月-日)
var dangqianriqi = new Date();
function getNowFormatDate(date) {
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
};
转换如/Date(1601420400000)/类型的日期
//转(年-月-日 时:分)
function getFDateTime(date) {
var d = eval('new ' + date.substr(1, date.length - 2));
var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
var ar_time = [d.getHours(), d.getMinutes(), d.getSeconds()];
for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
for (var i = 0; i < ar_time.length; i++) ar_time[i] = dFormat(ar_time[i]);
return ar_date.join('-') + ' ' + ar_time.join(':');
};
//转(年-月-日)
function getFDate(date) {
var d = eval('new ' + date.substr(1, date.length - 2));
var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
return ar_date.join('-');
};
//转(时:分)
function getFTime(date) {
var d = eval('new ' + date.substr(1, date.length - 2));
var ar_time = [d.getHours(), d.getMinutes()];
for (var i = 0; i < ar_time.length; i++) ar_time[i] = dFormat(ar_time[i]);
return ar_time.join(':');
};
function dFormat(i) {
return i < 10 ? "0" + i.toString() : i;
};
2020-09-28 09:20只取年月日或时分(年-月-日或时:分)
//取年-月-日
function getFDate(date) {
var d = new Date(date);
var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
return ar_date.join('-');
};
//取时:分
function getFTime(date) {
var d = new Date(date);
var ar_time = [d.getHours(), d.getMinutes()];
for (var i = 0; i < ar_time.length; i++) ar_time[i] = dFormat(ar_time[i]);
return ar_time.join(':');
};
function dFormat(i) {
return i < 10 ? "0" + i.toString() : i;
};