0

How do I change date format settings for the Composite.News Package? (or perhaps the whole Composite C1 Site)

I would like to use the date format YYYY/M/D for all news instead of the standard M/D/YYYY

I´ve been looking in the Razor Functions (NewsList & NewsLatest) but cant find any date format related settings.

1 Answers1

0

There is no setting like this in the package out-of-the-box.

You can however change that. In the Razor function "Composite.News.NewsList" find the helper method "Date" (currently at the end of the file).

@helper Date(DateTime date)
{
    <span class="text-muted">
        <span class="icon-calendar"></span>
        @date.ToShortDateString()
    </span>
}

Replace:

@date.ToShortDateString()

with:

@date.ToString("yyyy/M/d")

or follow the guide on other format specifiers here https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx

Of course, this will be hard-coded. So you can add another parameter to the Razor function and use its value instead:

[FunctionParameter(Label = "Date format", Help = "...", DefaultValue = "yyyy/M/d")]
public string DateFormat { get; set; }

...

@helper Date(DateTime date)
{
    <span class="text-muted">
        <span class="icon-calendar"></span>
        @date.ToString(DateFormat)
    </span>
}

Thus you can use other format specifiers via the function properties in the GUI.

wysocki
  • 731
  • 5
  • 7