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 ?
To know all possible ways, check this link out.
I've put all the DEMOS here...
<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>
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>
$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
var d1=new Date();
d1.toString('MM-dd-yyyy');
var startDate = new Date();
var result = Globalize.format(startDate, "MM/DD/YYYY");
I assume that you are using Globalize.
What you should do is to format the date, not parse it.
var startDate = new Date();
var result = Globalize.format(startDate, "MM/DD/YYYY");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With