For example, if the ex-dividend date is next Monday, and I buy the stock on next Monday, would I get the dividend? Or would the person who sold the stock to me get the dividend?
Here is the definition of Ex-dividend date from the SEC:
The linked document discusses weekend, and holidays involved in the calculation.
The difference between the record date and the ex-dividend is to allow for the three days of settlement.