Friday, 27 June 2014

Date conversion within JsRender using Moment.js

Moment.js rocks!

I dare say I've said it before and I know I'll say it again but it really, really rocks! You know what else rocks? JsRender also rocks!

Why do they rock? They rock because they allow me to write Converters which are a line long and allow me to convert US formated dates to UK formated dates with this:

$.views.converters({
    ukDate: function (value) {
        return moment(value).format("DD/MM/YYYY");
    }
});

This means that I use this line in my JsRender template:

<dt>Date Recieved</dt>
<dd>{{ukDate:Date_Received__c}}</dd>

And the US formated date gets converted without me having to worry!

That's why Moment.js and JsRender rock!