yii2:why my calender changed to Gregorian after upload?

72 Views Asked by At
 $time = Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->date]);

in my localhost $time is persian (jalali) and after upload $time is english(Gregorian )

how can i change my $time to jalali (perisan)????

1

There are 1 best solutions below

0
Mehran On

You should set the timestamp property time_zone as shown bellow:

date_default_timezone_set('Asia/Tehran');

Another way you can use this function to convert Gregorian to Persian after upload:

public function gregorianToPersian($gregorian)
{
    date_default_timezone_set('Asia/Tehran');
    $gregorian = date_parse($gregorian);
    $persian = $this->fromGregorian([$gregorian['year'], $gregorian['month'], 
    $gregorian['day'], $gregorian['hour'], $gregorian['minute'], 
    $gregorian['second']])->toPersian('en')->asDateTime();
    return $persian;
}