jquery tmpl格式化日期?

时间:2011-06-22 16:59:10

标签: jquery json templates

我正在使用jquery tmpl在表中显示一堆结果。其中一个是我在模板中输出的日期:

<td class="textAlignRight">${EffectiveDate}</td>

但它的格式如“/ Date(1245398693390)/”。如何更改它,使其格式化为m / dd / yyyy h:mm tt?

3 个答案:

答案 0 :(得分:19)

只需使用函数格式化日期:

模板:

<td class="textAlignRight">${GetDate(EffectiveDate)}</td>

功能:

function GetDate(jsonDate) {
  var value = new Date(parseInt(jsonDate.substr(6)));
  return value.getMonth() + 1 + "/" + value.getDate() + "/" + value.getFullYear();
}

答案 1 :(得分:2)

<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td>

答案 2 :(得分:2)

我建议使用这样的东西:

<script type='text/javascript'>
    Date.prototype.CustomFormat = function () {
        return this.getMonth() + 1 + "/" + this.getDate() + "/" + this.getFullYear();
    };
</script>

...

<td class="textAlignRight">${EffectiveDate.CustomFormat()}</td>
相关问题