Consider this scenario:
During normal market hours, you buy a security 1 day before the ex dividend date. You sell this security in after market trading that same day.
Who gets the dividend, you or the after hours buyer?
Does it depend on the specific security?