Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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 dateFormattMMDDYYY = function(yourDate) {
    var date = new Date(yourDate);
    var dd = date.getDate();

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

    if (mm
        mm = '0' + mm;
    }

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

    return date;
}

Example 2 related to date format Javascript - DD-MM-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
        dd = '0' + dd;
    }

    if (mm
        mm = '0' + mm;
    }

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

    return date;
}

Example 3 related to date format JavaScript - MM/DD/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
        dd = '0' + dd;
    }

    if (mm
        mm = '0' + mm;
    }

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

    return date;
}
Example 4related to date format JavaScript - MM-DD-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
        dd = '0' + dd;
    }

    if (mm
        mm = '0' + mm;
    }

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

    return date;
}

Share the post

JavaScript date format yyyy-mm-dd

×

Subscribe to Angular 2 Javascript Asp.net C# Sql Server Knockoutjs Angularjs Kendo Ui Html 5 Web Api Wpf Wcf Etc.

Get updates delivered right to your inbox!

Thank you for your subscription

×