function loadTable() { //function
var reportedFromDate = document.IssueForm.reportedFromDate.value; //getting value from input field
alert(reportedFromDate); //displays dd-mm-yy 31-02-13
}
我想将其转换为31-FEB-13
function loadTable() { //function
var reportedFromDate = document.IssueForm.reportedFromDate.value; //getting value from input field
alert(reportedFromDate); //displays dd-mm-yy 31-02-13
}
我想将其转换为31-FEB-13
检查以下代码段:
function loadTable() { //function
var reportedFromDate = document.IssueForm.reportedFromDate.value;
alert(reportedFromDate); // your format
var parts=reportedFromDate.split("-");
var date=parts[0];
var month=parts[1];
var year=parts[2];
var mon=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEPT","OCT","NOV","DEC"];
var m=parseInt(month);
alert( date +"-"+mon[m-1]+"-"+year); // required format
}
您需要执行一些步骤:
1. Create one array of months like
var months = ["JAN","FEB"....,"DEC"];
2. Split the date with (-) seperator
3. Take the 1st index (not 0) and search through the Array (months)
4. Display the formatted date.