Bourgain-Brezis-Mironescu formula for magnetic operators