I usually get my best work done in the ~4 hours of my morning, then find that I get much less done the rest of the day after lunch. I got very worried that I waste too much time at work though, and that I'm too easily distracted, so I started looking into it more.
I found that common tips like eating breakfast, sleeping well, and listening to music helped a little, but it wasn't very reliable and I still tended to lose focus very easily. I finally got a suspicion and spoke with my doctor, concerned that I might have ADHD. I've been taking Adderall for a while now, and found that it really helped me a lot. It's hard to describe, but its like it makes competing distractions quieter, so I can choose which thing to focus on and it makes it easier for me to slip into "the zone" so many programmers talk about: a wonderful distraction-immune state of pure productivity.
So if I just take my medicine, I can get about 4 or so productive hours: a strong morning and a decent few hours in the afternoon. If I do like I'm supposed to, eat well and sleep enough, that gets me up to about 5-6 good hours, and if I'm just having a good day (say I have a very clear problem to work through) then I can be productive the whole 7-8 hours of actual working time.
Anyway, I'm not saying its for everyone, nor am I suggesting it as a catch-all solution to productivity problems. But for some people, read up on the signs of ADHD, talk with a doctor and maybe that can help. I know I went for years thinking I was just lazy or undisciplined and that's why I couldn't focus on school work or work until I decided that just maybe it shouldn't be nearly physically painful to focus on what I should be doing and sought help.