In most cases, only if he is not on-duty.
Most transoceanic flights have flight times exceeding the amount of time a pilot is allowed by most aviation regulators to be at the yoke in one stretch. In the U.S., the FAA mandates a maximum of 8 hours in one continuous block, which can be extended by a few hours if the pilot is then allowed to rest for a longer-than-normal time afterward. Qantas Flights 7 and 8 between Dallas and Sydney are in the air for sixteen and a half hours in one continuous flight.
In these situations, the aircraft has multiple flight crews, and one crew will relieve the other in mid-flight. While not on duty, pilots may do almost anything the confines of the plane allow, including retiring to a special pilots' quarters, usually tucked in an out-of-the-way place on the plane, not obvious to passengers. These quarters, while not exactly palatial, are still of a level that even first class passengers would envy:
The cabin crew also have an hours limit that is exceeded by most long-hauls, and they also have their own space to get away from their jobs, though it's slightly more spartan:
While on-duty, the FAA regs used to allow for "in-seat rest", allowing the "pilot not flying" to rest his eyes for a while if nothing interesting was going on. However, an incident with Northwest Airlines Flight 188 in 2009 was the final nail in the coffin for any allowance for sleeping in the cockpit. ATC lost all communication with this flight for almost two hours while it was heading to Minneapolis. By the time contact was re-established, the plane was 150 miles past the airport and still at cruising altitude. In the interim, F-16s were readied to intercept (but never launched) as the plane had been feared hijacked. While the pilots insist they were using laptops to go over airline schedules (a breach of Northwest's parent Delta's cockpit policies, not to mention basic flight fundamentals), other theories suggest they simply fell asleep. Unfortunately, the CVR only had the last 30 minutes of the flight in its data buffer, while the critical time to determine what they'd been doing before radio contact was re-established would have been at least an hour prior to landing.
British Airways and Qantas as well as a few other airlines do allow pilots on duty to sleep in the cockpit, as long as one crew member is awake and at the controls. However, they cannot do so while flying in U.S.-controlled airspace.