Transformers use the magnetic effect of generation, but first change the electrical energy into magnetism using an electromagnet.
You may remember that electricity requires a changing magnetic field to be generated, and so the electromagnet in a transformer must produce a changing magnetic field.
There are two possible ways of doing this. First, turn the electricity on and off continuously (not very easy). Secondly, use a source of electricity which changes direction repeatedly (easy! Use AC!).