Electrodynamics in curved spacetime: 3 + 1 formulation