简体   繁体   English

将日期转换成不同格式的jQuery / JavaScript

[英]convert the date into different format jquery/javascript

function loadTable() { //function 
    var reportedFromDate = document.IssueForm.reportedFromDate.value; //getting value from input field
    alert(reportedFromDate); //displays dd-mm-yy 31-02-13
}

I want to convert it as 31-FEB-13 我想将其转换为31-FEB-13

check following snippet : 检查以下代码段:

  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
    }

You need to follow some steps: 您需要执行以下步骤:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM