Hi, previously in yii1 i have used the localisation concept, the code is
public static function getClientLocalDateTime($dateTime, $format=self::ANSI_DATE_TIME_FORMAT) {
$dateTime = DateTime::createFromFormat($format, $dateTime); // input date and format
$userTimeZone = new DateTimeZone(self::getClientTimeZoneName()); // client timezone name
$dateTime->setTimeZone($userTimeZone); // convert to client date format
return $dateTime; // returns the o/p for client local timezone
}
But in yii2, want to do the same. When i use the same code its displaying the error of
Class 'common\components\DateTime' not found
so i have changed that into
$dateTime = Yii::$app->formatter->asDatetime($dateTime, $format);
then
$dateTime->setTimeZone($userTimeZone); // convert to client date format
then now i’m getting the php fatal error of
Call to a member function setTimeZone() on a non-object
Please help me how to solve this issue?