0

I want to convert row.visitDate to string. Now it will display like - /Date(1581376680000)/

View

<code>
    <div> @Html.DropDownListFor(m => m.AmcvId, new SelectList(""), "--Select Visit--", new { @id = "AmcvId", @class = "form-control" })</div>

</code>
<script>
     $.get("/ComplaintRegistration/GetAmcVisitList", { AmcId: $("#AmcId").val() }, function (data) {
                        $("#AmcvId").empty();
                        $.each(data, function (index, row) {
                            $("#AmcvId").append("<option value='" + row.AmcVisitId + "'>" + row.VisitDate + "</option>")
                        });
                    });
 </script>

Controller:

public ActionResult GetAmcVisitList(int AmcId)
{
    List<AMCVisitDetails> AmcVisitList = new List<AMCVisitDetails>();
    AmcVisitList = db.AmcVisitDetails.Where(t => t.AmcId== AmcId).ToList();

    return Json(AmcVisitList, JsonRequestBehavior.AllowGet);    
}

3 Answers 3

1

I'm parsing .net dates like this.

var date = new Date(parseInt(row.visitDate.substr(6)));

date.toLocaleDateString();
Sign up to request clarification or add additional context in comments.

Comments

0

The value displayed which looks like some random garbage number is actually a timestamp value represented in miliseconds. Inorder to convert Timestamp to proper human readable date, simply pass this Timestamp to the Date constructor.

var visitDate = new Date(row.AmcVisitId); //new Date(1581376680000) gives "Mon Feb 10 2020 18:18:00 GMT-0500 (Eastern Standard Time)"

Now you can format it as you prefer for displaying it in the Page.

Comments

0

use this

new Date(row.VisitDate).toLocaleString()

1 Comment

This will not work, result same as it is . $.each(data, function (index, row) { $("#AmcvId").append("<option value='" + row.AmcVisitId + "'>" + new Date(row.VisitDate).toLocaleString() + "</option>") });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.