Date to String object conversion

html, javascript, jquery

Solution

To know all possible ways, check this link out.

I've put all the DEMOS here...

STANDARD JS:

<script type="text/javascript">
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months start with zero
    var curr_year = d.getFullYear();
    document.write(curr_month + "/" + curr_date + "/" + curr_year);
</script>

MOMENT.JS:

Download here...

<script>    
    var a = moment([2010, 1, 14, 15, 25, 50, 125]);
    a.format("MM/DD/YYYY,");    
</script>

Don't want to download, simply add this line:

<script src="http://momentjs.com/downloads/moment.min.js"></script>

jQuery UI:

$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));

IE:

var d1=new Date();
d1.toString('MM-dd-yyyy');

Globalize:

var startDate = new Date();
var result = Globalize.format(startDate, "MM/DD/YYYY");

Problem

I have use the following code snippet to convert the Date object to string . ``` var startDate = new Date(); var result = Globalize.parseDate(startDate, "MM/DD/YYYY"); ``` but it will return the null value. How to convert the Date object to string specific format ?

Original source

Related problems