Hey, I also agree with its being dissociation. Mainly because that is what I was told it was when I was having the exact things you're describing here. But like most have said its best to get it checked out by a medical professional.
It's a really hard thing to just snap yourself out of, but it is treatable with DBT(dialectical behavior therapy). At least that's what was suggested to me. And when you do come out of the world and back to reality it helps to getup and move around and focus your mind on doing something. Which might be difficult if you suffer from depression like I do, but even just something as small as walking up some stairs and then going to sit back down will really help. If youre around people often, and you trust them, you can ask them to help you out when you dissociate by being gentle with you and light,y rubbing your arm and telling you what day it is and the time and where you are, over and over until you come back to reality. I've also found that writing about where I go is pretty helpful, and if you have a therapist you can all about the places and figure out a pattern.
Best of luck to you in figuring this out.
:

:
Kelly