Converting date string from dashes to forward slashes

前端 未结 3 1780
长情又很酷
长情又很酷 2021-01-25 04:57

I am trying to convert my dashed date 2013-12-11 to 2013/12/11 using the following function:

function convertDate(stringdate)
{
    // Internet Explorer does not         


        
3条回答
  •  攒了一身酷
    2021-01-25 05:37

    Your function is working as expected convertDate(myDate) is returning the / value off the date.

    Your problem seems to be your logging

    var myDate = '2013-12-11';
    console.log('Before', myDate); //2013-12-11
    
    convertDate(myDate);
    console.log('After', myDate); //2013-12-11 
    

    Your function returns a value so convertDate(myDate) is just returning and doing nothing. And your console log for after is just returning the same date as before.

    If you change your console log to

    console.log('After', convertDate(myDate)); //2013-12-11 
    

    You will get the expected result, or set myDate to the new value

      myDate = convertDate(myDate);
        console.log('After', myDate); //2013-12-11 
    

提交回复
热议问题