【问题标题】:How to convert json date from angular in asp.net mvc [duplicate]如何在asp.net mvc中从角度转换json日期[重复]
【发布时间】:2017-07-28 11:27:20
【问题描述】:

我在控制器中有一个动作方法,它返回 json 结果为:

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

还有一个 Angular js 中的代码,例如:

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;
        });
    };
});

输出是:

如何将 json DATE 转换为字符串?

【问题讨论】:

标签: angularjs json asp.net-mvc


【解决方案1】:

使用它来转换 JSON 日期

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

结果:1​​995 年 10 月 14 日星期六 23:45:00 GMT+0530(印度标准时间)

【讨论】:

    【解决方案2】:

    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>

    看看这个Angular Moment JsMoment Js for JSON date 可能会有帮助。

    您可以使用moment js将其转换为以下内容

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

    要使用它,您必须在项目中添加 Angular moment,上面的链接中解释了如何使用 nuget 或 bower 或 npm 添加。

    请在上面找到 sn-p 以及

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 2016-05-26
      相关资源
      最近更新 更多