I want to convert timestamps
to dates
and truncate minute
and seconds
,then, convert it back to timestamps
. I know I can do that with some mathematical algorithm like timestamps/60
or timestamps/3600
, but I want to use Python
provided functions. My code is like below. I tried two methods:
for timeStamp in lineTimeStamps:
#first try
day1=datetime.datetime.\
fromtimestamp(float(timeStamp)).strftime("%Y-%m-%d %H")
timestamp1 = time.mktime(day1)
#second try
day2=datetime.datetime.\
fromtimestamp(float(timeStamp)).\
replace( minute=0, second=0, microsecond=0).timetuple()
timestamp2 = time.mktime(day2)
In timestamp1 = time.mktime(day1)
, I got the error like:
TypeError: Tuple or struct_time argument required
In timestamp2 = time.mktime(day2)
, I got the error like:
OverflowError: mktime argument out of range
How can I convert it back to timestamps
?