为什么DateTime::createFromFormat()方法未定义


Why does DateTime::createFromFormat() method turn out to be undefined?

下面是PHP代码。

public function storeUser($name, $email, $password, $str_birthday) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted_password"]; // encrypted password
    $salt = $hash["salt"]; // salt
    $dob = DateTime::createFromFormat('m/d/Y', $str_birthday)->format('Y-m-d');
    $result = mysqli_query($this->db->connect(), "INSERT INTO users(unique_id, name, email, encrypted_password, birthday, salt, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$dob', '$salt', NOW())");
    // check for successful store
    if ($result) {
        // get user details
        $result = mysqli_query($this->db->connect(), "SELECT * FROM users WHERE email = '$email'");
        // return user details
        return mysqli_fetch_array($result);
    } else {
        return false;
    }
}

在浏览器上运行该命令后,它表示以下部分未定义。

$dob = DateTime::createFromFormat('m/d/Y', $str_birthday)->format('Y-m-d');

但我已经找到了很多建议,可以使用这种方法更改日期格式,将其存储到MySQL数据库中。

实现这一点的更简单方法:

$dob = date("Y-m-d", strtotime($str_birthday));