convert dd/mm/yyyy to mm/dd/yyyy in javascript

前端 未结 12 1107
深忆病人
深忆病人 2020-12-15 18:49

I want to convert dd/mm/yyyy to mm/dd/yyyy in javascript.

12条回答
  •  渐次进展
    2020-12-15 19:53

    use this function

    function dateFormat(existingFormat,neededFormat,existingSeperator,newSeperator,dateValue)
    {
            var exst    =    existingFormat.toLowerCase().split(existingSeperator);
            var d       =    dateValue.split(existingSeperator);
            d[exst[0]]  =    d[0];  d[exst[1]]=d[1];   d[exst[2]]=d[2];
    
            var newst    =    neededFormat.toLowerCase().split(existingSeperator);
            newDate      =    d[newst[0]] +newSeperator+d[newst[1]] +newSeperator+d[newst[2]];
            return(newDate); 
    
    }
    var dd    =    dateFormat('dd/yy/mm','mm/dd/yy','/','-','30/87/05');//dateFormat(existingFormat,neededFormat,existingSeperator,newSeperator,dateValue)
    

    //use same name for date month and year in both formats

    You can use this function for converting any format date(including month date year only) to any format. :)

提交回复
热议问题