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?
To format a JavaScript date into “yyyy-mm-dd” format, use the toISOString() method.
The simplest way to convert your date to the yyyy-mm-dd format, is to do this: var date = new Date("Sun May 11,2014"); var dateString = new Date(date.getTime() - (date.getTimezoneOffset() * 60000 )) .toISOString() .split("T")[0];
format = All input formats valid for jQuery. format. date are valid for this method. The defaut format is MM/dd/yyyy HH:mm:ss.
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();
}
<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With