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

后端 未结 15 1588
攒了一身酷
攒了一身酷 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:35

    Use the Moment.js library http://momentjs.com/ It will save you a LOT of trouble.

    moment().format('DD-MMM-YYYY');
    
    0 讨论(0)
  • 2020-12-01 03:37

    Pass data changeFormate(15/07/2020)

      changeFormate(date) {
    let month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    let incomingDateChnge: any = new Date(date);
    let incomingDay = incomingDateChnge.getDate();
    let incomingMonth = incomingDateChnge.getMonth();
    
    let incomingYear = incomingDateChnge.getFullYear();
    if (incomingDay < 10) {
      incomingDay = '0' + incomingDay;
    }
    
    incomingDateChnge = incomingDay + ' ' + month_names[incomingMonth] + ' ' + incomingYear;
    return incomingDateChnge;
     }
    
    0 讨论(0)
  • 2020-12-01 03:40

                var today = new Date();           
    
                var formattedtoday = today.getDate() + '-' + (today.getMonth() + 1) + '-' + today.getFullYear();
                
                alert(formattedtoday);

    0 讨论(0)
提交回复
热议问题