For example I want to say "I ran 5km in 23mins 59 secs" or "It took me 23mins 59 secs to run 5k" or "It took me an hour to tidy my room" etc etc etc.
It's possibly a little different for each of your examples even though they mean the same thing. However, the ones with "took" seem to emphasize more effort than the ones with "in", so it depends if you want to focus on that or not.
- I ran 5km in 23mins 59secs → 23分59秒 で 5キロメートル走った
- It took me 23mins 59 secs to run 5k → 5キロメートル走るのに23分59秒 かかった