-1

I am fetching a date from web service. Here is the code:

<a href="#" id="loadData">Load Data</a>
        <script type="text/javascript">
            var qry = "http://localhost:2084/WcfDataService1.svc/tb_Programs";
            $("#loadData").click(function() {
                //alert(1);
                $('#status').text("Loading Programs...");
                    $.getJSON(qry, function (results) {
                    $.each(results.d, function (i, item){
                        var line = "<div>" + Date(item.PrgFromDate) + ":" + Date(item.PrgToDate) + "</div>";
                        $("#games").append(line);
                    });
                    $('#status').text("");
                });
            });
        </script>

The output of this is: Thu May 28 2015 16:55:31 GMT+0530 (India Standard Time):Thu May 28 2015 16:55:31 GMT+0530 (India Standard Time)

How can I get just the date in dd/mm/yyyy?

2 Answers2

0

You don't need jquery for that. There is javascript library called moment.js

You can do a lot with that library.

You can download it from here http://momentjs.com/

user786
  • 2,727
  • 3
  • 24
  • 45
0

Try this instead:

var PrgFromDate = newDate(item.PrgFromDate);
var frmDate2show = PrgFromDate.getDate()+'/'+(PrgFromDate.getMonth()+1) +'/' + PrgFromDate.getFullYear();
var PrgToDate = newDate(item.PrgToDate);
var toDate2show = PrgToDate.getDate()+'/'+(PrgToDate.getMonth()+1) +'/' + PrgToDate.getFullYear();
var line = "<div>" + frmDate2show + ":" + toDate2show + "</div>";
$("#games").append(line);

var date = new Date("Thu May 28 2015 16:55:31 GMT+0530 (India Standard Time)");

var newDate = date.getDate() + '/' + (date.getMonth()+1) + '/' + date.getFullYear();

alert(newDate);
Jai
  • 71,335
  • 12
  • 70
  • 93