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.

 Answers

55

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
 
oroshnivskyy
answered 7 Months ago
96

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) {
    //$value->format('Y-m-d')       
}
Wednesday, March 31, 2021
 
CAMason
answered 7 Months ago
28

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
 
peixotorms
answered 7 Months ago
24

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
 
mattltm
answered 4 Months ago
62

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
 
braindamage
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 :