gpt4 book ai didi

date - 如何在 JavaScript 中将日期从 dd mon yyyy 拆分为 dd mon?

转载 作者:行者123 更新时间:2023-11-28 20:58:17 24 4
gpt4 key购买 nike

我使用 JavaScript 创建了一个表,其中包含 ID,name出生日期 等列。我还对该表进行了排序。

但现在我必须将日期从 dd mon yyyy 拆分为 dd mon

例如:从1989年11月4日11月4日

我应该做什么?

这是代码...我只是想更新它...

<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
//searcg the ouput array to make sure not to use duplicate rows
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" ><b> Employee Birthday Information </b></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="20" 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> Priyanka </td>
<td> 29 Dec 1990 </td>
</tr>
<tr>
<td> 15 </td>
<td> Jack </td>
<td> 7 Mar 1987 </td>
</tr>
<td> 4 </td>
<td> Joe </td>
<td> 4 June 1986 </td>
</tr>
<td> 48 </td>
<td> Julie </td>
<td> 3 July 1989 </td>
</tr>
</table>

最佳答案

var now = new Date();

now.format("dd mmm");

查看更多示例 here

关于date - 如何在 JavaScript 中将日期从 dd mon yyyy 拆分为 dd mon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11663337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com