Using similarity transformations we construct explicit nontrivial solutions of nonlinear Schrödinger equations with potentials and nonlinearities depending both on time and on the spatial coordinates. We present the general theory and use it to calculate explicitly nontrivial solutions such as periodic (breathers), resonant, or quasiperiodically oscillating solitons. Some implications to the field of matter waves are also discussed.