With the development of intelligent transportation system (ITS), owing to its flexible connectivity structures and communication network topologies, connected cruise control (CCC), increasing the situation awareness of the autonomous vehicle without redesigning the other vehicles, is an advanced cruise control technology attracted extensive attention. However, due to the uncertain traffic environment and the movement of the connected vehicles, the leader speed is typically highly dynamic. In this paper, taking the uncertain time-varying leading vehicle velocity and communication delays into consideration, an optimal CCC algorithm is proposed for both near-static case and general dynamic control cases. First, the analysis for discrete-time error dynamics model of the longitudinal vehicle platoon is performed. Then, in order to minimize the error between the desired and actual states, a linear quadratic optimization problem is formulated. Subsequently, in near-static control case, an efficient algorithm is proposed to derive the solution of the optimization problem by two steps. Specifically, the online step calculates the optimal control scheme according to the current states and previous control signals, and the off-line step calculates the corresponding control gain through backward recursion. Then, the results are further extended to the general dynamic control case where the leader vehicle moves at an uncertain time-varying velocity. Finally, simulation results verify the effectiveness of the proposed CCC algorithm.