This paper proposes a procedure for obtaining an optimal trajectory for robot manipulators along specified tasks (spot welding, drilling ...). The purpose is to obtain smooth trajectories with minimum time using spline cubic functions under a various kinematic and/or dynamic constraints, taking into account a full dynamic model of robot manipulator and with a large number of via points. This procedure is based on the optimization by a genetic algorithm of a vector which represents only a time intervals in order to find the best objective function. Two examples illustrated with numerical details for a two-link planar arm and six-link manipulators, for the former, comparisons with an alternative optimization solver are exposed.