对称日?凑凑热闹

<!DOCTYPE html>

<html>
<head>
<title>对称日计算</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<script>
function getSymmetricalDate(year) {
y = '' + year;
if (y.length != 4) return false;
var y, m, shortM, d, shortD, date, isSymDate;
m = y.substr(2, 2).split('').reverse().join(''); //获取y的第三第四位字符并倒转
d = y.substr(0, 2).split('').reverse().join('');
shortD = (d.charAt(0) == '0') ? d.charAt(1) : d;
shortM = (m.charAt(0) == '0') ? m.charAt(1) : m;
date = new Date(y, shortM - 1, shortD);
isSymDate = (y == date.getFullYear()) && (m - 1 == date.getMonth()) && (d == date.getDate());
return isSymDate ? '' + y + m + d : false;
}
</script>
</head>
<body>
<p>对称日:</p>
<script>
var symmetricalDate = [];
for (var year = 1000; year <= 9999; year++) {
var isSymDate = getSymmetricalDate(year);
if(isSymDate)symmetricalDate.push(getSymmetricalDate(year));
}
document.write(symmetricalDate.join('<br />'));
</script>
</body>
</html>

posted @ 2011-11-02 23:55  Arliang  阅读(165)  评论(0编辑  收藏  举报