Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery tmpl formatting a date?

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?

like image 963
Rush Frisby Avatar asked Jun 22 '11 16:06

Rush Frisby


People also ask

How to set Date in mm dd yyyy format in JavaScript?

To format a JavaScript date into “yyyy-mm-dd” format, use the toISOString() method.

How to get Date in yyyy mm dd format in JavaScript?

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];

What is the date format in jQuery?

format = All input formats valid for jQuery. format. date are valid for this method. The defaut format is MM/dd/yyyy HH:mm:ss.


2 Answers

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();
}
like image 123
Mark Coleman Avatar answered Oct 07 '22 19:10

Mark Coleman


<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td>
like image 38
Phil Avatar answered Oct 07 '22 18:10

Phil