401K/HSA contribution across the end of the year

401K contributions (deferred salary) gets deducted from my paychecks. The last pay period was December 15- December 29 2023, but the paycheck date is January 7 2024. Does the amount deducted in this paycheck / payperiod go towards 2023 401K contribution, or 2024? Same question for HSA contribution (but I suspect a different answer).