alxgh / yii2-jdate

Jalali date & time extension for yii2
14 stars 13 forks source link

Mysql Time format #3

Closed bepehr closed 8 years ago

bepehr commented 10 years ago

Hi , when i want to convert time from mysql i get this error

DateTime::__construct(): Failed to parse time string (@2014-11-03 20:48:44) at position 8 (-): Double timezone specification

in C:\xampp\htdocs\adnasor\vendor\mohammad-mahdy\yii2-jdate\DateTime.php at line 23 14151617181920212223242526272829303132 { if(! is_string($dateFormat)) { throw new InvalidParamException( "Date format is inavlid! " . "This must be a string." ); }

    $dateTime = new \DateTime('@' . ($timeStamp ?: time()),  new \DateTimeZone('Asia/Tehran'));
    $dateTime->setTimeZone(new \DateTimeZone('Asia/Tehran'));
    list($jalaliYear, $jalaliMonth, $jalaliDay) = $this->toJalaliDate(
        $year   = $dateTime->format('Y'),
        $month  = $dateTime->format('m'),
        $day    = $dateTime->format('d'));

    $res = '';
    $skipNextCahr = false;
    for ($i = 0; $i < strlen($dateFormat); $i++) {
alxgh commented 9 years ago

@bepehr In first parameter you should send date form like Y-m-d H:i:s and if you want convert date , use strtotime function then send that as seconde parameter.

Like It:

$this->jdate->date('Y-m-d H:i:s', strtotime($yourTimeFromDb);