How to extract hours, minutes and secods from datetime.fromtimestamp

Viewed 31

from response i get date time stamp like this '1663935188183'. I used python datetime.fromtimestamp() function and print date in full format '2022-09-23 14:13:08.183000'

My question is. Can i extract from function above just hours, minutes and secods ?

1 Answers

You can try this solution

>> from datetime import datetime

# Be carefule this will raise ValueError: year 54698 is out of range
# you have to divide timestamp by 1e3 if your timestamp is in milliseconds
>> timestamp = 1663935188183/1e3
>> date = datetime.fromtimestamp(timestamp)
>> date.hour, date.minute, date.second
(14, 13, 8) 
Related