When citing a journal paper, should I use the online publication year or the print publication year?
As StrongBad said, the general rule is to follow the guidelines outlines by the publication venue.

If there is none, then as a rule of thumb, cite the journal version. The reason depends on the type of online publication:


When the paper was an early access version of the later journal paper and
thus identical, the journal paper in some sense replace the online access
version.
When the 2012 paper was posted at arXiv.org or the like, then the later
journal version went through peer reviewing, whereas the earlier version did
not. So the journal version can easily be more mature.


Note that one role of citations is to assign academic credit. Credit towards a paper that appeared in a reputable journal counts a bit more, so citing the journal version is also a courtesy to the author(s).

If for some reason, for your paper, it is of importance who had an idea first (e.g., when you give a chronological overview of related work), you can just add a note like "An earlier version of the paper appeared in XYZ in 2012" to the bibliography entry of the journal version to make that clear.