I've only had that problem when I was in your shoes (very new to the sex game). Classic advice is to 'think about baseball' - don't ask me why
I've also seen references to exercising the PC muscle - which controls things like urine flow - to delay ejac. There also are creams out there for this that I've seen when purchasing condoms, but I have no direct experience with them. If I were you, I'd do a web search on "PC muscle" and I'm sure you'll find information out there somewhere on this. Also, controlling your breath rate (slower) and depth (deeper) will help you stay a bit more relaxed, and this should help you too.
I am significantly older than you, so I will give you another piece of advice or knowledge that one usually only gets from experience - which is that the 30-40 minutes thing (or longer) is overrated/overestimated by men. I can do that with no problem at all, but I have to tell you, it's not all that appreciated by most women because I usually don't need to go that long (unless she can multiple). If you're 'hittin' it' right, most women will not take nearly that long to get off, and although some of them will want to keep going for the multiple orgasms if they're capable, a lot of them cannot really do this, and so she'll be ready for you to orgasm reasonably soon after she does... and if you don't, she will ask you "what's wrong?" thinking that you don't find her that exciting or something.