i've just started using jQuery Templates as my javascript template engine. My question is, how can i format a date (returned from a ASP.NET Json ActionResult) in the form:
/Date(1288709830000)/
I tried doing the following:
{{= $.format(new Date(parseInt(comment.DateCreated.substr(6))), 'd')}}
Note the above uses the new jquery globalization plugin to add the $.format
method. Also note that {{= comment.DateCreated }}
is long hand for saying ${comment.DateCreated}
.
I'd really appreciate it if you could help.
format = All input formats valid for jQuery. format. date are valid for this method. The defaut format is MM/dd/yyyy HH:mm:ss.
jQuery.tmpl() is its official templating plugin. Developed by Microsoft, under MIT/GPL licence.
jQuery Template is applied to data objects or arrays and is rendered into the HTML using jQuery functions for DOM manipulation. In the following example, we will describe how JQuery template works. First, we must add reference to the JQuery library and JQuery Template.
The string format should be: YYYY-MM-DDTHH:mm:ss. sssZ , where: YYYY-MM-DD – is the date: year-month-day. The character "T" is used as the delimiter.
This is what I used
var formatDate = function (datetime) {
var dateObj = new Date(parseInt(datetime.replace("/Date(", "").replace(")/", ""), 10));
return dateObj.format("dd-MMM-yyyy"); //01-Jun-2001
}
And this in my JQuery Template
${formatDate(InceptionDate)}
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