2011-06-22 12 views
8

Używam jquery tmpl, aby pokazać kilka wyników w tabeli. Jednym z nich jest data, która jestem wyprowadzanie używając w moim szablonu:jquery tmpl formatuje datę?

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

ale to wychodzi sformatowany jak „/ Data (1245398693390) /”. Jak mogę to zmienić tak, aby wychodziło sformatowane jak m/dd/rrrr h: mm tt?

Odpowiedz

19

Wystarczy użyć funkcji do formatowania daty:

Szablon:

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

Funkcja:

function GetDate(jsonDate) { 
    var value = new Date(parseInt(jsonDate.substr(6))); 
    return value.getMonth() + 1 + "/" + value.getDate() + "/" + value.getFullYear(); 
} 
+0

gdzie dokładnie trzeba wkleić funkcji getdate()? w 'ready'? – Neo

2
<td class="textAlignRight">{{= format(new Date(parseInt(EffectiveDate.substr(6))), 'd') }}</td> 
2

polecam użyć czegoś takiego:

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

...

<td class="textAlignRight">${EffectiveDate.CustomFormat()}</td> 
Powiązane problemy