We have established the relations between the baryon-baryon scattering phase shifts and the two-particle energy spectrum in the elongated box. We have studied the cases with both the periodic boundary condition and twisted boundary condition in the center of mass frame. The framework is also extended to the system of nonzero total momentum with periodic boundary condition in the moving frame. This will be helpful to extract the phase shifts in the continuum from lattice QCD data using asymmetric volumes.