Time reversal of linear and nonlinear water waves