The legal drinking age in New York City is 21 (as it is everywhere in the United States), and most bars and restaurants will ask you for ID if you appear under-age. In most cases, people under 21 aren't allowed in bars, but they are allowed in restaurants where alcohol is served.
Liquor cannot be served by bars and restaurants in New York City from 4 a.m. to 8 a.m. daily, though some bars/restaurants choose to have their "last call" earlier than 4 a.m.
New York City liquor laws limit the sale of wine and spirits to liquor stores, but beer is available in convenience stores, delis and grocery stores. Beer sales are permitted 24 hours a day. Liquor stores cannot sell alcohol from midnight to 9 a.m. daily, except Sundays when sales are only permitted from noon until 9 p.m.
In New York City, it is illegal to drink alcoholic beverages in public places (this also includes possession of an open container of alcohol). This is true whether or not you are of legal age, and applies to drinking alcohol in parks, streets, etc.