I found an annoying issue where the date rendered from the Display Templates in one of the Office 365 sites was always out by the timezone. Initially I thought maybe the regional settings where wrong, but after further investigation I found the problem.
The event item in the calendar had an Event Date of 31th of Oct at 9am.
Given this part of the Display Template
var eventDate = $getItemValue(ctx, "EventDate");
The value of
10/30/2017 10:00:00 PM (a string).
So the display template had been updated to convert it to a date.
var displayEventDate = new Date(eventDate);
When rendered to the page the date was incorrectly:
30 Oct at 10pm
There where 2 issues:
1. Incorrect Managed Property Mappings
The Managed Property
EventDate had been mapped to 2 crawl properties.
ows_fAllDayEvent. This caused a change to the way SharePoint stored the data in the crawl property. It stored it as the string value
10/30/2017 10:00:00 PM
When there is only 1 crawl property mapped, the date value gets stored as:
The Display Template attempted to convert the string value, but had no information about the timezone, so it assumed it was a local date when in fact it was a UTC Time.
The Date converted was (10/30/2017 10:00:00 PM+11:00). So the time zone offset had really been subtracted from the date.
By removing the additional mapped crawl property
ows_fAllDayEvent and performing a full site reindex from https://somesite.sharepoint.com/_layouts/15/srchvis.aspx, the data was saved in the index in the ISO format eg;
Note: Removing the additional mapping was not enough. The re-index was needed.
Then all the dates where correctly rendered in the users local timezone. Sweet :)