In .cshtml views the date field is automatically formatted. To take advantage of the automatic date format, in Sitefinity .NET Core Renderer, you must reference the date in the views, using the FormatDate HTML helper.
.cshtml
FormatDate
To do this, in the .cshtml files, render the date object in the following way:
On the frontend, the .NET Core Renderer supports the following ways for calculating date and time:
The default format for these dates is “d MMM, hh:mm tt”. You can change this, by modifying the ServerDateFormat property in the appSettings.json file of the Renderer in the following way:
“d MMM, hh:mm tt”
ServerDateFormat
appSettings.json
You can replace the formatting logic entirely, by providing a custom implementation of the Progress.Sitefinity.AspNetCore.Mvc.Rendering.IDateTimeFormatter interface in the following way:
Progress.Sitefinity.AspNetCore.Mvc.Rendering.IDateTimeFormatter
To switch to client-side date and time calculation, you must modify the DateFormatSource property in the appSettings.json file of the Renderer in the following way:
DateFormatSource
This automatically adds a script on the frontend of each widget that has a call to @Html.FormatDate. This script traverses the entire page and looks for a specific marker to convert the dates.
@Html.FormatDate
To replace the default formatting logic on the client, you must include a script tag like the following:
RECOMMENDATION: We recommend placing the <script> tag in the <head> tag of your root layout file.
<script>
<head>
NOTE: The language for the formatting is read from the html tag. Therefore, it is important to set the lang attribute. The Renderer pages have a dynamically generated lang attribute, based on the requested language of the page.
html
lang
Sign up for our free beginner training. Boost your credentials through advanced courses and certification. Register for Sitefinity training and certification.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important