使用Javascript / JQuery解析自动生成的.NET日期对象 [英] Parsing a Auto-Generated .NET Date Object with Javascript/JQuery

查看:137
本文介绍了使用Javascript / JQuery解析自动生成的.NET日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一些帖子,但不是这个具体问题的答案。

There are some posts on this, but not an answer to this specific question.

服务器返回此信息:/ Date( 1304146800000)/

我想根本不更改服务器端代码,而是解析包含在内的日期。净生成的JSON对象。这似乎并不难,因为它看起来几乎就在那里。然而似乎没有快速解决方案,至少在这些论坛中。

I would like to not change the server-side code at all and instead parse the date that is included in the .Net generated JSON object. This doesn't seem that hard because it looks like it is almost there. Yet there doesn't seem to be a quick fix, at least in these forums.

从之前的帖子中听起来这可以使用REGEX完成,但REGEX和我是在酒吧里冷冷地凝视着对方的老敌人。

From previous posts it sounds like this can be done using REGEX but REGEX and I are old enemies that coldly stare at each other across the bar.

这是唯一的方法吗?如果是这样,有人可以指向我适合此任务的REGEX参考吗?

Is this the only way? If so, can someone point me to a REGEX reference that is appropriate to this task?

问候,

Guido

推荐答案

Robert的链接很好,但我们应该努力回答这个问题,而不仅仅是发布链接。

The link from Robert is good, but we should strive to answer the question here, not to just post links.

这是一个快速的功能,可以满足您的需求。 http://jsfiddle.net/Aaa6r/

Here's a quick function that does what you need. http://jsfiddle.net/Aaa6r/

function deserializeDotNetDate(dateStr) {
  var matches = /\/Date\((\d*)\)\//.exec(dateStr);

  if(!matches) {
    return null;
  }

  return new Date( parseInt( matches[1] ) );
}

deserializeDotNetDate("/Date(1304146800000)/");

这篇关于使用Javascript / JQuery解析自动生成的.NET日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆