-2
我正在嘗試更改日期格式,請您幫助我將日期格式更改爲此日期,2016年2月12日11:00?更改日期格式功能
這裏是下面的代碼:
function nicetime(a, out) {
var d = Math.round((+new Date - a)/1000),
fuzzy = '',
n = 'mins',
d = d < 0 ? 0 : d;
if (out == 1) {
return d;
} else if (out == 0) {
var chunks = new Array();
chunks[0] = [60 * 60 * 24 * 365, 'year', 'years'];
chunks[1] = [60 * 60 * 24 * 30, 'month', 'months'];
chunks[2] = [60 * 60 * 24 * 7, 'week', 'weeks'];
chunks[3] = [60 * 60 * 24, 'day', 'days'];
chunks[4] = [60 * 60, 'hr', 'hrs'];
chunks[5] = [60, 'min', 'mins'];
var i = 0,
j = chunks.length;
for (i = 0; i < j; i++) {
s = chunks[i][0];
if ((xj = Math.floor(d/s)) != 0) {
n = xj == 1 ? chunks[i][1] : chunks[i][2];
break;
}
}
fuzzy += xj == 1 ? '1 ' + n : xj + ' ' + n;
if (i + 1 < j) {
s2 = chunks[i + 1][0];
if (((xj2 = Math.floor((d - (s * xj))/s2)) != 0)) {
n2 = (xj2 == 1) ? chunks[i + 1][1] : chunks[i + 1][2];
fuzzy += (xj2 == 1) ? ' + 1 ' + n2 : ' + ' + xj2 + ' ' + n2;
}
}
fuzzy += ' ago';
return fuzzy;
}
}
嗨,什麼是你的了''和「出去」? – Yoplaboom
請花時間把問題縮小到讓人們更容易理解你想要的東西。刪除不需要的問題的任何代碼。 – rghome
你可以試試這樣:[JSFiddle](https://jsfiddle.net/RajeshDixit/snw738pq/) – Rajesh