During the cyclic operation process of hydraulic excavators, based on manual experience, issues such as low work efficiency and high energy consumption can cause significantly high wearing of the joints of the excavator; this markedly affects the service life of the excavator. To solve such issues, we propose a secondary trajectory optimization method based on time–energy consumption that enables the excavator to conduct smooth, efficient, and low-energy-consumption work. Considering different weight coefficient values and obtaining the optimal time–energy trajectory, we compare the above-mentioned results with those obtained through skilled manual operation of hydraulic excavators. The experimental results demonstrate that through reasonable and effective planning of each joint movement, the large jerk that occurs during joint movement processes may be effectively avoided, the working efficiency of the excavator is improved, unnecessary energy consumption is reduced, and the excavator can operate autonomously under stable conditions. These results verify the effectiveness and feasibility of the proposed method.