That equation works anywhere, gravity has no part it in, just what you see.
Uh, but I think you may be reffering to potential energy from your last sentance or two. If you are, gravitational potential energy is the potential energy something has on planet Earth for example. If an object is suspended in the air, it has potential energy because it can fall.
This equation is E=mgd where E is energy in joules, m is mass, g is acceleration due to gravity and d is distance from the refference point. The refference point would usually be the surface of the Earth, so you could find how much energy something would gain by being dropped to the ground. At sealevel on earth, gravity is 9.8m/s. On other planets this would be different.
Or you wern't talking about this at all, and it was a complete waste.