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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^