In .cshtml views the date field is automatically formatted. To take advantage of the automatic date format, in Sitefinity ASP.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 ASP.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
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important