SharePoint Online 2013 Design Templates displaying local NL date for a managed property in all browsers

When trying to display a date in a Display Template within SharePoint, I have found that the browsers respond differently to certain function calls.

The issue was that the client wants the date to display in all browsers as: 9 maart 2015, in the dutch locale.

Given the context, ctx, and a managed property called MyDate.

1. Get the date:

var getMyDate = $getItemValue(ctx, “MyDate”)

2. Turn the variable into a date variable:

var theDate= new Date(getMyDate);

Using toLocaleDateString – gives correct format in Chrome but incorrect in IE11

var stringDate = theDate.toLocaleDateString(‘nl-NL’, {day: ‘numeric’, month: ‘long’, year: ‘numeric’});

Displays in Google Chrome: 9 maart 2015
Displays in IE11:  maandag 9 maart 2015

Using Srch.U.toFormattedDate – gives incorrect format

var stringDate = Srch.U.toFormattedDate(theDate);

Displays in Google Chrome: maandag 9 maart 2015
Display in IE11: maandag 9 maart 2015

Using Srch.U.toFormattedDate(DATE,’ShortDatePattern’) – gives incorrect format

var stringDate = Srch.U.toFormattedDate(theDate,’ShortDatePattern’);

Displays in all browsers: 9-3-2015

Using format(‘d MMMM yyyy’) – gives correct format but incorrect locale

var stringDate = theDate.format(‘D MMMM YYYY’);

Displays in all browsers: 9 March 2015

__________________________________________________________________

Using Moment-with-locales.min.js – gives correct format and correct locale

moment.locale(‘nl’);

var stringDate = moment(theDate).format(‘D MMMM YYYY’)

Displays in all browsers: 9 maart 2015

Comments are closed.