简体   繁体   中英

How to format date from word to number? Ex. Nov 4, 2004 to 11/04/2004 using JQuery?

I am new to Jquery can anyone help me or give me sample on this one. How to format date from word to number? Ex. Nov 4, 2004 to 11/04/2004 using JQuery?

Thanks in advance..

 var now = new Date('Nov 4, 2004'); var date = now.getDate(); var year = now.getFullYear(); var month = now.getMonth(); var date1 = date < 10 ? "0"+date : date; console.log(month+1+"/"+date1+"/"+year) 

  1. Add 1 to month because it will start at 0

Here you go.

html

    <input id="thedate" type="text" /><br />
    <input id="converteddate" type="text" /><br />
    <input id="thesubmit" type="button" value="Submit" />

JS

$(function(){
    //Nov 4, 2004
    $('#thedate').datepicker({
        dateFormat: 'M d, y',
        altField: '#converteddate',
        altFormat: 'mm/dd/yy'
    });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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