Asked  7 Months ago    Answers:  5   Viewed   38 times

I have this part of the function, which gives me name of the months in English. How can I translate them to my local language (Serbian)?

$month_name = date('F', mktime(0, 0, 0, $i));

Where $i is the number of the month (values 1 - 12). See also PHP:mktime.



You should use setlocale():

setlocale(LC_TIME, 'fr_FR');
$month_name = date('F', mktime(0, 0, 0, $i));

In this case it would set it to French. For your case it should be one of the following:

  1. sr_BA - Serbian (Montenegro)
  2. sr_CS - Serbian (Serbia)
  3. sr_ME - Serbian (Serbia and Montenegro)
Wednesday, March 31, 2021
answered 7 Months ago

You could also take a look at the DatePeriod class:

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')

Which should get you an array with DateTime objects.

To iterate

foreach ($period as $key => $value) {
Wednesday, March 31, 2021
answered 7 Months ago

Could you use IntlDateFormatter::getPattern to get the pattern? I don't know about strftime, but I would use the suggestion of formatting with a pattern MMMM to get the month name, through each month. Looks like php.intl doesn't expose the data directly.

Wednesday, March 31, 2021
answered 7 Months ago

You need to call DateInterval::format() to display that difference as a string.

echo $diff->format('%d days');

See the manual for all of the available formatting options.

Wednesday, July 7, 2021
answered 4 Months ago

On login the user information will be stored in Yii::$app->user->identity variable.

For more information have a read through the User Authentication documentation in the official guide.

Wednesday, August 11, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :