Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

A solution to getting your date and time in your locale


Go to End


1727 Views

Avatar
yurigoul

Community Member, 203 Posts

2 August 2013 at 3:38am


My example is based on German and Silverstripe 3.

When you have a datefield in your cms that you use to set a date and you want to set the date in a locale different from en_US. In your controller add the function:

function localDate($myDate) {
	$newLocale = setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
	return strftime('%d. %B %Y', strtotime($myDate));
}

In your template use $localDate($myDateField) and you are golden.

Change the de_DE to your own locale. Change '%d. %B %Y' to something that looks nice to you: http://www.php.net/manual/en/function.date.php

When getting the time from a DateTimeField use $myDateTime.Time24() in your templates together with the localDate() function because there seems to be a problem with getting the minutes.