JavaScriptで日付ddmonyyyyをmondd形式に変換する方法は?javascriptを使用してテーブルを作成しました。このテーブルには、ddmonyyyy形式の日付列が含まれています。その形式をddmonに変換し、月ごとに並べ替えたいと思います。何をすべきか?plzは私を助けます。
これが私のコードです...
<script>
var now = new Date();
now.format("dd mmm");
var allNums = false;
var allDates = false;
var lastSort = -1;
var absOrder = true;
function setDataType(inValue) {
var isDate = new Date(inValue);
if (isDate == "NaN") {
if (isNaN(inValue)){
inValue = inValue.toUpperCase();
allNums = false
allDates = false
return inValue;
}
else {
allDates = false
return parseFloat(1*inValue);
}
}
else {
allNums = false
return inValue ;
}
}
function sortTable(col){
if (lastSort == col){
absOrder ? absOrder = false : absOrder = true
}
else{
absOrder = true
}
lastSort = col
allTR = document.getElementById("dataTable").childNodes[0].childNodes
totalRows = allTR.length
colToSort = new Array()
colArr = new Array()
copyArr = new Array()
resultArr = new Array()
allNums = true
allDates = true
for (x=1; x < totalRows; x++){
colToSort[x-1] = setDataType(allTR[x].childNodes[col].innerText)
colArr[x-1] = allTR[x]
}
for (x=0; x<colToSort.length; x++){
copyArr[x] = colToSort[x]
}
if (allNums){
colToSort.sort(numberOrder)
}
else if (allDates){
colToSort.sort(dateOrder)
}
else{
colToSort.sort(textOrder)
}
for(x=0; x<colToSort.length; x++){
for(y=0; y<copyArr.length; y++){
if (colToSort[x] == copyArr[y]){
boolListed = false
for(z=0; z<resultArr.length; z++){
if (resultArr[z]==y){
boolListed = true
break;
}
}
if (!boolListed){
resultArr[x] = y
break;
}
}
}
}
for (x=0; x<resultArr.length; x++){
allTR[x+1].swapNode(colArr[resultArr[x]])
}
}
function numberOrder(a,b){
absOrder ? rVal = b - a : rVal = a - b
return rVal
}
function dateOrder(a,b){
absOrder ? rVal = Date.parse(a) - Date.parse(b) : rVal = Date.parse(b) - Date.parse(a)
return rVal;
}
function textOrder(a,b){
if (a.toString() < b.toString()){
absOrder ? rVal = -1 : rVal = 1
}
else{
absOrder ? rVal = 1 : rVal = -1
}
return rVal
}
</script>
<body style="background-color:AliceBlue">
<h1 style="color:Blue" align="center"><div id="header" style="background-color:LightCyan;"> Employee Birthday Information </div></h1>
<br/>
<br/>
<h><b> Sort by : </b></h>
<input type="radio" onclick="sortTable(0)" name=sort> Employee Id </input>
<input type="radio" onclick="sortTable(1)" name=sort> Employee Name </input>
<input type="radio" onclick="sortTable(2)" name=sort> Employee Birthdate </input>
</br>
</br>
<table id="dataTable" align="center" cellpadding="10" cellspacing="10" bgcolor="LightCyan">
<tr>
<th>Employee Name</th>
<th>Employee Id</th>
<th>Employee Birthdate</th>
</tr>
<td> 1 </td>
<td> Smita </td>
<td> 4 Nov 1989</td>
</tr>
<tr>
<td> 26 </td>
<td> Julie </td>
<td> 29 Dec 1990 </td>
</tr>
<tr>
<td> 15 </td>
<td> Rashmi </td>
<td> 7 Mar 1987 </td>
</tr>
<td> 4 </td>
<td> Jack </td>
<td> 4 June 1986 </td>
</tr>
<td> 48 </td>
<td> Soniya </td>
<td> 3 July 1989 </td>
</tr>
<td> 32 </td>
<td> John </td>
<td> 3 June 1989 </td>
</tr>
<td> 45 </td>
<td> Prajakta </td>
<td> 9 Aug 1989 </td>
</tr>
<td> 7 </td>
<td> Apeksha </td>
<td> 6 Feb 1989 </td>
</tr>
</table>