1

I have a action method in controller which returns json result as:

public ActionResult GetByDids(int id)
{
    AngularMVCEntities _db = new AngularMVCEntities();
    var emps = _db.Employees.Where(x => x.Did == id).ToList();
    return Json(emps, JsonRequestBehavior.AllowGet);
}

And a code in angular js like:

app.controller('employeesController', function ($scope, $http) {
    $scope.GetEmployeesByDid = function (did) {
        alert('Get Employees By Id' + ' ' + did);
        $http.get('/Employees/GetByDids', { params: { id: did } }).then(function       (response) {
            $scope.Emps = response.data;
        });
    };
});

Output is: enter image description here

How to convert the json DATE to string?

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
Sumit Bhattarai
  • 308
  • 2
  • 19
  • You need to extract the relevant date info from that string value and use it to build a Date object as needed. See this http://stackoverflow.com/questions/42074532/issue-with-datetime-jquery-asp-net-mvc/42075212#42075212 – Shyju Mar 08 '17 at 02:59
  • [ASP.NET MVC JsonResult Date Format](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format) –  Mar 08 '17 at 03:01

2 Answers2

1

Use this to convert JSON date

new Date(parseInt("/Date(813694500000)/".substr(6)))

Result : Sat Oct 14 1995 23:45:00 GMT+0530 (India Standard Time)

amit
  • 406
  • 4
  • 6
0

var date = moment("/Date(1198908717056-0700)/").format("YYYY-MM-DD");
console.log(date);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Take a look at this Angular Moment Js and Moment Js for JSON date it might be helpful.

You can convert this as the below using moment js

var date = moment("/Date(1198908717056-0700)/").format("YYYY-MM-DD");

To use this you have to add Angular moment in your project and which is explained in above link how to add using nuget or bower or npm.

Please find above snippet as well

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Curiousdev
  • 5,668
  • 3
  • 24
  • 38