Get current date in DD-Mon-YYY format in JavaScript/Jquery

后端 未结 15 1705
攒了一身酷
攒了一身酷 2020-12-01 03:06

I need to get the date format as \'DD-Mon-YYYY\' in javascript. I had asked a question, and it got marked duplicate to jQuery date formatting

But, the answers provi

15条回答
  •  春和景丽
    2020-12-01 03:14

    //convert DateTime result in jquery mvc 5 using entity fremwork 
    
    const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    
    
    function DateAndTime(date) {
    
        var value = new Date
            (
            parseInt(date.replace(/(^.*\()|([+-].*$)/g, ''))
        ); 
        var dat = value.getDate() +
            "-" +
            monthNames[value.getMonth()] +
            "-" +
            value.getFullYear();
    
        var hours = value.getHours();
        var minutes = value.getMinutes();
        var ampm = hours >= 12 ? 'PM' : 'AM';
        hours = hours % 12;
        hours = hours ? hours : 12; // the hour '0' should be '12'
        minutes = minutes < 10 ? '0' + minutes : minutes;
        var strTime = hours + ':' + minutes + ' ' + ampm;
        return { Date: dat, Time: strTime };
    }
    // var getdate = DateAndTime(StartDate);
    //var Date = getdate.Date;//here get date
    //var time = getdate.Time;//here get Time
    //alert(Date)
    

提交回复
热议问题