日期:2014-05-16 浏览次数:20449 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<ul id="test">
<li>2011-1-1</li>
<li>2011-1-7</li>
<li>2011-1-2</li>
<li>2011-3-1</li>
<li>2011-2-1</li>
</ul>
<script type="text/javascript">
var lis = document.getElementById('test').getElementsByTagName('li'); //这里根据实际情况自己修改下
var arrMS = new Array();
var d = new Date();
d.setHours(0,0,0,0);
for(var i = 0; i < lis.length; i ++) {
//日期转毫秒数
var strDate = lis[i].innerHTML;
var arrTmp = strDate.split('-');
arrMS.push(d.setFullYear(arrTmp[0],arrTmp[1] - 1,arrTmp[2]));
}
arrMS.sort();
var html = '';
for (i = 0; i < arrMS.length; i ++) {
d.setTime(arrMS[i]);
html += '<li>' + d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + '</li>\n';
}
document.getElementById('test').innerHTML = html;
</script>
</body>
</html>