The accepted answer already explains how the calculation must be made and provides a sample code in Haskell; however, I will also leave here a simple snippet of code in Java, removing all the Haskell boilerplate (and can be easily ported to any other language).
/**
* Converts from POSIX time to slot.
*
* @param time The POSIX time to be converted (in seconds).
*
* @return The matching slot.
*/
static long posixTimeToSlot(long time)
{
long slotWhenSlotChangedTo1Sec = 1598400;
long timeWhenSlotChangedTo1Sec = 1595967616L;
long remainingSeconds = time - timeWhenSlotChangedTo1Sec;
return slotWhenSlotChangedTo1Sec + remainingSeconds;
}