The dynamic critical exponent z is determined numerically for the d-dimensional XY model (d = 2, 3, and 4) subject to relaxational dynamics and resistively shunted junction dynamics. We investigate both the equilibrium fluctuation and the relaxation behavior from nonequilibrium towards equilibrium, using the finite-size scaling method. The resulting values of z are shown to depend on the boundary conditions used, the periodic boundary condition, and fluctuating twist boundary condition (FTBC), which implies that the different treatments of the boundary in some cases give rise to different critical dynamics. It is also found that the equilibrium scaling and the approach to equilibrium scaling for the the same boundary condition do not always give the same value of z. The FTBC in conjunction with the finite-size scaling of the linear resistance for both type of dynamics yields values of z consistent with expectations for superfluids and superconductors: z = 2, 3/2, and 2 for d = 2, 3, and 4, respectively.