How to change date format using jQuery?

前端 未结 4 1101
长情又很酷
长情又很酷 2020-12-15 07:31

I have a date in a format like this fecha2.value = \'2014-01-06\', but I want to change the format to this \'01-06-14\' using jQuery.

How c

4条回答
  •  执念已碎
    2020-12-15 08:22

    I dont think you need to use jQuery at all, just simple JavaScript...

    Save the date as a string:

    dte = fecha.value;//2014-01-06
    

    Split the string to get the day, month & year values...

    dteSplit = dte.split("-");
    yr = dteSplit[0][2] + dteSplit[0][3]; //special yr format, take last 2 digits
    month = dteSplit[1];
    day = dteSplit[2];
    

    Rejoin into final date string:

    finalDate = month+"-"+day+"-"+year
    

提交回复
热议问题