public static function getUserId($username)
{
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
        ->select($db->quoteName('id'))
        ->from($db->quoteName('#__users'))
        ->where($db->quoteName('username') . ' = ' . $db->quote($username));
    $db->setQuery($query, 0, 1);

    return $db->loadResult();
}

And you can use JUserHelper:

$username = 'admin';
$userId    = JUserHelper::getUserId($username);

echo $userId;