I've written my own calendar generation software that's pretty reliable. I can send you the text file I generate that contains all historical dates if that's helpful? Something else to be aware of is that there are half days that occur near thanksgiving and Christmas where the exchange closes at 1:00pm. These are documented on the NYSE and Nasdaq websites.
Can I ask why? The one's mentioned here already handle regular holidays, irregular ones, half-days, different markets and timezones.
There's no simple way to do it, as someone said here, if you got historical market data from somewhere then if it's got no data for some day, most likely it's a holiday. Unfortunately often times it's just shitty, missing data, so you gotta do some statistics, using multiple stocks (hopefully on the same market / exchange), if they ALL miss that day then it's definitely a market holiday.