Typically on a 401K the employer pulls the contribution from your paycheck. I haven't seen an employer that offers the option to designate contributions for the prior year. Therefore you would need to make the contribution before the 12-31. That being said, I've had the company "true up" contribution after 12-31. Look at your plan carefully. Some plans only match the monthly contribution and don't offer a true up. That means if you meet your $17,500 early you could loose your match for the remaining months.
IRA contributions can run into the next year. You just need to make sure you designate the correct year. It's a March or April date.
Remember, there are income limits on your Roth.
This post was edited on 6/26 at 5:43 am