November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
In your article page template (view) use sny of your needed DateTime format strings. Assuming that CurrentPage will give you back article page and there is property with date and time in it:
@Model.CurrentPage.Published.ToString("yyyy-mm-dd")
here is list of various format strings.
You can also add a display template under Views/Shared/DisplayTemplates with DateTime as a model (and DateTime?), then you can do as Valdis suggested there instead, so that it's applied to every DateTime property. You do, however, need to make sure that you render the DateTime as either Html.DisplayFor or Html.PropertyFor (not as Model.CurrentPage...)
BR,
Marija
...and also consider why that date gets formatted like that in the first place. Maybe you are building a Swedish site but using English pages in Episerver or similar?
In that case the root issue might be worth fixing to run the site in correct culture...
Just speculating a bit :)
It really feels like something is missing here.
Where is it you want the date to show as 2016-11-14?
The solutions Valdis and Marija supplied has to do with showing any date on your actual site.
I can't help wondering if it is the date format in the property mode in cms edit mode you are refering to?
In which case i think it is connected to the culture of the editor/administrator that is logged in.
Hi guys,
In my index.cshtml right is show "Starttid14 December 2016 kl. 09:00". I would like it show the month in swedish format with small alphabet.
my code look like this <dd><time datetime="2016-05-12">@Model.CurrentPage.StartDate.ToString("dd MMMM yyyy kl. HH:mm")</time></dd>
How can I get the swedish moth format?
Hi, Katharina,
Shouldn't you just change the format in ToString()?
<dd><time datetime="2016-05-12">@Model.CurrentPage.StartDate.ToString("yyyy-MM-dd HH:mm")</time></dd>
Or are you looking into a solution for all templates?
Also, what format do you get (on a Swedish CMS page) if you just render this: @Html.DisplayFor(m => m.CurrentPage.StartDate)? (instead of Model.CurrentPage.StartDate....)?
BR,
Marija
Hi Marija,
I need to get result like this: Starttid14 december 2016 kl. 09:00
In my Model, I have public virtual DateTime StartDate {get; set;}, so the editor can pick a date and time in editor mode.
First in my index.cshtml I tried @Html.PropertyFor(m => m.CurrentPage.StartDate), then I got the result like this: Starttid12/14/2016 9:00:00 AM
Then I tried out this code @Model.CurrentPage.StartDate.ToString("dd MMMM yyyy kl. HH:mm"), the I got the result like this: Starttid14 December 2016 kl. 09:00
It was quite close to what I would like but just it still not show a swedish format with small alphabet. I think I must do something with Cultureinfo but I don't know exactly yet how I can implement that.
...and also consider why that date gets formatted like that in the first place. Maybe you are building a Swedish site but using English pages in Episerver or similar?
In that case the root issue might be worth fixing to run the site in correct culture...
If you have a single language on your site, make sure that language is Swedish on your site. You can check that in admin. If you have English (which I suspect you have), the culture will be set to "en" and dates and times will be formatted accordingly. Best solution is then to switch master language to Swedish rather than doing custom formatting on every date/time (although that works as well).
Also remember to test with a month that hasn't the same name in both Swedish and English :)...October would be good for instance...
Indeed, check what CurrentPage.Language is, if it is anything else then 'sv-SE' you really should look over your site and page languages.
For every site you create in Episerver cms you can define in which languages/cultures it should be available and which one should be the master (which can be used as fallback).
If it is as Daniel Ovaska suggests and you only want swedish, once you set it up correctly with swedish as master then all pages you create under that site will be in swedish.
It all comes down to activating the built-in support for translation and localization episerver provides. While it is possible to manually override the culture everywhere it is not recommended in any way, if someone decides to translate the site into english you will regret it for a long time.
Hello,
I'm a new in Episerver. It would be appreciate if you guys could give me a tips how to custom Date format. In my current article page show as Updated 14/11/2016. But I would like to change the format to show as Updated 2016-11-14. Any idea?