Skip to content

Instantly share code, notes, and snippets.

@tamitutor
Created January 17, 2012 22:33
Show Gist options
  • Save tamitutor/1629439 to your computer and use it in GitHub Desktop.
Save tamitutor/1629439 to your computer and use it in GitHub Desktop.
Handlebars Date Helper - ASP.NET Date to JavaScript Date
var offset = new Date().getTimezoneOffset() * 60 * 1000;
function parseAspNetUTCDateToJSDate(jsonDate) {
var parsedDate = new Date(parseInt(jsonDate.substr(6)) + offset);
return parsedDate;
}
Handlebars.registerHelper('date', function (date, block) {
return parseAspNetUTCDateToJSDate(date).toDateString(); //Return a shortened version of the date
});
<table class="interventions-view fill">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>Begin Date</td>
<td>Status</td>
<td>Result</td>
</tr>
</thead>
<tbody>
{{#each Records}}
<tr>
<td>
{{Name}}
</td>
<td>
{{Type}}
</td>
<td>
{{date StartDate}}
</td>
<td>
{{Name}}
</td>
<td>
<img src="/static/img/{{ResultImage}}" title="{{ResultName}}" alt="{{ResultName}}"/>
</td>
</tr>
{{/each}}
</tbody>
</table>
@tamitutor
Copy link
Author

Of course this is assuming your using UTCDate format on the ASP.Net side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment