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,199
  • 18
  • 61
  • 80

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
  • 39,942
  • 9
  • 80
  • 101
2
<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td>
Phil
  • 4,004
  • 4
  • 22
  • 39
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,278
  • 3
  • 26
  • 28