What is the logic that leads to conservation of energy from time invariance? [duplicate]

This question already has an answer here:

I have read different accounts of time invariance leading to the conservation of energy, but have not encountered the specific logical explanation for it. Can someone provide it?

marked as duplicate by Qmechanic♦Nov 21 '17 at 8:03

• You haven't yet encountered Noether's theorem? – Alfred Centauri Nov 21 '17 at 3:06
• In reality Noether's theorem shows time invariance and conservation of energy are coexistent, but that is based on a number of assumption we made in the first place to get to the field theory & EL formalism. You are subtly getting back the same assumptions you put in. – Señor O Nov 21 '17 at 3:26
• @SeñorO, I've asked the OP a question. What is your intention? – Alfred Centauri Nov 21 '17 at 4:08
• The OP seems under the impression that time invariance alone will lead to conservation of energy, so my intention is to let him know that he will find Noether's theorem is really a formalism to extract conservation laws rather than a way to derive them with simpler assumptions than would be necessary otherwise. – Señor O Nov 21 '17 at 4:52
• Possible duplicate of Prove energy conservation using Noether's theorem – Chris Nov 21 '17 at 4:52

In classical mechanics, in the Hamiltonian formalism, the Hamiltonian of a system (the Legendre transformation of the Lagrangian in canonical moments) is the time evolution generator. In general, if the Hamiltonian $H$ (same for the Lagrangian) does not explicitly depends of the time (i.e.: $\frac{\partial H}{\partial t} = 0$) then $H$ is conserved (i.e.: $\frac{d H}{d t} = 0$). But the Hamiltonian is not always equal to the energy of a system!
In order to make sure $H$ is equal to the system's total energy, the following conditions must be met:
When those conditions are met, then $H=E$ and if $\frac{\partial H}{\partial t} = 0$ then $\frac{d H}{d t} = \frac{d E}{d t} = 0$ so the energy is conserved. Of course, in most cases, we have that $H=E$ but it is not in all cases. In conclusion: time invariance does not always mean energy conservation.