  We propose a new formula for the entropy of a dynamical black hole$-$valid to
leading order for perturbations off of a stationary black hole background$-$in
an arbitrary classical diffeomorphism covariant Lagrangian theory of gravity in
$n$ dimensions. In stationary eras, this formula agrees with the usual Noether
charge formula, but in nonstationary eras, we obtain a nontrivial correction
term. In general relativity, our formula for the entropy of a dynamical black
hole is $1/4$ of the horizon area plus a term involving the integral of the
expansion of the null generators of the horizon, which we show is $1/4$ of the
area of the apparent horizon to leading order. Our formula for entropy in a
general theory of gravity obeys a "local physical process version" of the first
law of black hole thermodynamics. For first order perturbations sourced by
external matter that satisfies the null energy condition, our entropy obeys the
second law of black hole thermodynamics. For vacuum perturbations, the second
law is obeyed at leading order if and only if the "modified canonical energy
flux" is positive (as is the case in general relativity but presumably would
not hold in general theories). We obtain a general relationship between our
formula for the entropy of a dynamical black hole and a formula proposed
independently by Dong and by Wall. We then consider the generalized second law
in semiclassical gravity for first order perturbations of a stationary black
hole. We show that the validity of the quantum null energy condition (QNEC) on
a Killing horizon is equivalent to the generalized second law using our notion
of black hole entropy but using a modified notion of von Neumann entropy for
matter. On the other hand, the generalized second law for the Dong-Wall entropy
is equivalent to an integrated version of QNEC, using the unmodified von
Neumann entropy for the entropy of matter.
