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

javascript date format dd-mm-yyyy
convert dd-mmm-yyyy to date in javascript
jquery get current date time format
typescript format date mm/dd/yyyy
javascript date format dd mmm yyyy hh:mm:ss
how to change date format from dd/mm/yyyy to mm/dd/yyyy in javascript
jquery date format
javascript date output format

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 provided in the question are to get the current date in "DD-MM-YYYY" format and not "DD-MON-YYYY". Secondly, I am not using datepicker plugin.

Can you please help me as if how to get the current date in "DD-Mon-YYYY" format.

There is no native format in javascript for DD-Mon-YYYY.

You will have to put it all together manually.

The answer is inspired from : How to format a JavaScript date

// Attaching a new function  toShortFormat()  to any instance of Date() class

Date.prototype.toShortFormat = function() {

    var month_names =["Jan","Feb","Mar",
                      "Apr","May","Jun",
                      "Jul","Aug","Sep",
                      "Oct","Nov","Dec"];
    
    var day = this.getDate();
    var month_index = this.getMonth();
    var year = this.getFullYear();
    
    return "" + day + "-" + month_names[month_index] + "-" + year;
}

// Now any Date object can be declared 
var today = new Date();


// and it can represent itself in the custom format defined above.
console.log(today.toShortFormat());    // 10-Jun-2018

Get current date in DD-Mon-YYY format in JavaScript/Jquery, There is no native format in javascript for DD-Mon-YYYY . You will have to put it all together manually. The answer is inspired from : How to format a JavaScript  This code snippet is for to get current date in DD-Mon-YYY format in JavaScript/Jquery.

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

moment().format('DD-MMM-YYYY');

JavaScript: Display the current date in various format, getDate(); let mm = today. getMonth()+1; const yyyy = today. getFullYear(); if(dd<10) { dd=`0${dd}`; } if(mm<10) { mm=`0${mm}`; } today = `${mm}-${dd}-${yyyy}`; console. The task is to format the current date in dd/mm/yyyy format by using JavaScript. We’re going to discuss few methods. First few methods to know. JavaScript getDate() Method: This method returns the day of the month (from 1 to 31) for the defined date. Syntax: Date.getDate() Return value:

You can use toLocaleDateString and hunt for a format that's close to DD-mmm-YYYY (hint: 'en-GB'; you just need to replace the spaces with '-').

const date = new Date();
const formattedDate = date.toLocaleDateString('en-GB', {
  day: 'numeric', month: 'short', year: 'numeric'
}).replace(/ /g, '-');
console.log(formattedDate);

jQuery - Get and Format Current Date using jQuery, jQuery code to format current date, how to format/display date in We will print date in DD/MM/YYYY, MM/DD/YYYY or DD MON YYY format on button clicks. <​script type="text/javascript"> $(document).ready(function(){ var date=new Date();​  jQuery Get Todays Date dd/mm/yyyy. JavaScript code snippet to get the current date in the format dd/mm/yyyy. The month is formatted to prefix with a zero (ie “04”) for single month figures.

I've made a custom date string format function, you can use that.

var  getDateString = function(date, format) {
        var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        getPaddedComp = function(comp) {
            return ((parseInt(comp) < 10) ? ('0' + comp) : comp)
        },
        formattedDate = format,
        o = {
            "y+": date.getFullYear(), // year
            "M+": months[date.getMonth()], //month
            "d+": getPaddedComp(date.getDate()), //day
            "h+": getPaddedComp((date.getHours() > 12) ? date.getHours() % 12 : date.getHours()), //hour
             "H+": getPaddedComp(date.getHours()), //hour
            "m+": getPaddedComp(date.getMinutes()), //minute
            "s+": getPaddedComp(date.getSeconds()), //second
            "S+": getPaddedComp(date.getMilliseconds()), //millisecond,
            "b+": (date.getHours() >= 12) ? 'PM' : 'AM'
        };

        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                formattedDate = formattedDate.replace(RegExp.$1, o[k]);
            }
        }
        return formattedDate;
    };

And now suppose you've :-

    var date = "2014-07-12 10:54:11";

So to format this date you write:-

var formattedDate = getDateString(new Date(date), "d-M-y")

Date (dd-mmm-yyyy), and time in terms of millisecond precision within 100 million days before or after 1/1/1970. 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 provided in the question are to get the current date in "DD-MM-YYYY" format and not "DD-MON-YYYY". Secondly, I am not using datepicker plugin.

Can be done with toLocaleDateString

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

<script>
const date = new Date();
const formattedDate = date.toLocaleDateString('en-GB', {
  day: '2-digit', month: 'short', year: 'numeric'
}).replace(/ /g, '-');
document.write(formattedDate);
</script>

JavaScript, var d = new Date("25-03-2015");. JavaScript Long Dates. Long dates are most often written with a "MMM DD YYYY" syntax like this:  The above code outputs the current date and time as shown: // output "Fri Oct 19 2018 17:10:12 GMT+0530 (IST)" JavaScript Date Time Format. The above shown date time is the default format. It’s not so straight to change JavaScript date time format. Change Date Format dd-mmm-yyyy

jQuery UI DatePicker, How to get current formatted date dd/mm/yyyy in JavaScript ? JavaScript getDate() Method: This method returns the day of the month (from 1 to 31) for the defined date. JavaScript getFullYear() Method: JavaScript getMonth() Method: JavaScript String slice() method: replace() method: Time Zones. When setting a date, without specifying the time zone, JavaScript will use the browser's time zone. When getting a date, without specifying the time zone, the result is converted to the browser's time zone. In other words: If a date/time is created in GMT (Greenwich Mean Time), the date/time will be converted to CDT

JavaScript Date Formats, You can get the current date and time in JavaScript using the Date object. To convert date to format dd-mmm-yyyy you need to extract the date, month use any other jQuery plugin for date time format change in JavaScript. Date Methods. When a Date object is created, a number of methods allow you to operate on it. Date methods allow you to get and set the year, month, day, hour, minute, second, and millisecond of date objects, using either local time or UTC (universal, or GMT) time.

How to get current formatted date dd/mm/yyyy in JavaScript , JavaScript code snippet to get the current date in the format dd/mm/yyyy. The month is formatted to prefix with a zero (ie “04”) for single month  In the following example, we will create a jQuery date object and show you how to format and present it into an element. Example of current date format in MM/DD/YYYY with jQuery The example below creates a date object and then formats the date into MM/DD/YYYY.

Comments
  • The currently accepted answer is overly complicated. I've edited another answer that I think answers your question better. Can you please take a look?
  • It will also bloat your code a lot and is unnecessary when JavaScript core can solve the problem without libraries.
  • Well yes. There is also the excellent date-fns library date-fns.org. I mean with today's npm packages it hardly makes sense to roll your own.
  • my output format is Dec-11,-2019 which is not expected. please help me out
  • You don't need to roll your own date functions. The Date object already has a method that does what the OP asked.
  • Using the same code as above ? => 'en-GB' ?
  • Yes, I used same format.
  • yes I understand the date format, but how can I convert current date to dd-mon-yyyy, Eg I want to get current date in 15-Dec-2014, format.
  • Normally this should work (tested in console): test = new Date(); test.format('d-M-Y')
  • agreed. this would be great but format is not a function