Could anyone please tell me when to use these sentences? Which one is more formal/better?

a. "(It is/was) nice meeting you!"

b. "(It is/was) nice to meet you!"


I'd say a is slightly warmer, less formal, but there is not really much difference.
They are equivalent, or very nearly. I agree with Nona's opinion of the little difference there is.

Personally, I say "Nice to meet you!" when I first meet someone, for example, at a party.
After speaking with them for a while, I may mingle with other guests.
When it's time to leave, I say, "Nice meeting you!"

(Pretty strange, isn't it? Emotion: smile )