Switch to a reference frame which moves with the center of mass the system. Consider a point on the spring at the COM of the system. Split the spring into two springs (use the fact that $k\propto 1/l$) at this point. Now, you have a point which is stationary (in com frame), and two blocks attached to it, both of which are vibrating. Find the time period of both oscillations (it'll be the same, $2\pi\sqrt{\frac{m_1}{k_1}}=2\pi\sqrt{\frac{m_2}{k_2}}$), and divide by 2 (since you only want the time in which it completes half a cycle)
Of course, this formula gives the direct answer:$$\text{time period of a two mass-spring system}=2\pi\sqrt{\frac{\mu}{k}}$$, where $\mu=\frac{m_1m_2}{m_1+m_2}$ is the reduced mass.