javascript 如何从json解析日期时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16723805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:45:07  来源:igfitidea点击:

How to parse date time from json?

c#javascriptjqueryjsonasp.net-mvc-3

提问by Atish Dipongkor - MVP

I have a Action Method like this

我有一个这样的操作方法

public ActionResult TodayJson()
        {
            DateTime today = DateTime.Today;
            return Json(today,JsonRequestBehavior.AllowGet);
        }

that returns me the the following value

返回给我以下值

"\/Date(1369332000000)\/"

How can I parse it in actual date time by the jquery or java script. Format should be like this dd-mm-yyyy

如何通过 jquery 或 java 脚本在实际日期时间解析它。格式应该是这样的 dd-mm-yyyy

回答by Adam Tal

Use this in your javascript (while jsonDate = "\/Date(1369332000000)\/"):

在你的 javascript (while jsonDate = "\/Date(1369332000000)\/") 中使用它:

var date = new Date(parseInt(jsonDate.substr(6)));
var formattedDate = date.format("dd-MM-yyyy");

Source: How do I format a Microsoft JSON date?

来源:如何格式化 Microsoft JSON 日期?