8

I am using jquery tmpl to show a bunch of results in a table. One of them is a date which I am outputting using this in my template:

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

but it comes out formatted like "/Date(1245398693390)/". How can I change it so that it comes out formatted like m/dd/yyyy h:mm tt?

Rush Frisby
  • 11,388
  • 19
  • 63
  • 83

3 Answers3

19

Simply use a function to format your date:

Template:

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

Function:

function GetDate(jsonDate) {
  var value = new Date(parseInt(jsonDate.substr(6)));
  return value.getMonth() + 1 + "/" + value.getDate() + "/" + value.getFullYear();
}
Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
2
<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td>
Phil
  • 4,134
  • 4
  • 23
  • 40
2

I would recommend to use something like this:

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

...

<td class="textAlignRight">${EffectiveDate.CustomFormat()}</td>
Pavlo Neiman
  • 7,438
  • 3
  • 28
  • 28