python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
DD-MM-YYYY

JavaScript date format yyyy-mm-dd

We can declare a date in the following ways -
1.      new Date();
2.      new Date(value);
3.      new Date(dateString);
4.      new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

To getDate() method returns the day in the specified date.
To getMonth() method returns the month in the specified date.
To getFullYear()method returns the year of the specified date.

Example 1 related to date format JavaScript - DD/ MM/YYYY

var dateFormattDDMMYYY = function (yourDate) {
    var date = new Date(yourDate);
    var dd = date.getDate();

    var mm = date.getMonth() + 1;
    var yyyy = date.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }

    if (mm < 10) {
        mm = '0' + mm;
    }

    date = dd + '/' + mm + '/' + yyyy;

    return date;
}

Example 2 related to date format JavaScript - DD-MM-YYYY

var dateFormattDDMMYYY = function (yourDate) {
    var date = new Date(yourDate);
    var dd = date.getDate();

    var mm = date.getMonth() + 1;
    var yyyy = date.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }

    if (mm < 10) {
        mm = '0' + mm;
    }

    date = dd + '-' + mm + '-' + yyyy;

    return date;
}

Example 3 related to date format JavaScript - MM/DD/YYYY

var dateFormattMMDDYYY = function (yourDate) {
    var date = new Date(yourDate);
    var dd = date.getDate();

    var mm = date.getMonth() + 1;
    var yyyy = date.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }

    if (mm < 10) {
        mm = '0' + mm;
    }

    date = mm + '-' + dd + '-' + yyyy;

    return date;
}
Example 4 related to date format JavaScript - MM-DD-YYYY
var dateFormattMMDDYYY = function (yourDate) {
    var date = new Date(yourDate);
    var dd = date.getDate();

    var mm = date.getMonth() + 1;
    var yyyy = date.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }

    if (mm < 10) {
        mm = '0' + mm;
    }

    date = mm + '-' + dd + '-' + yyyy;

    return date;
}
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions