1

Given a timestamp (in past) I would like to calculate the timestamp of the "next midnight", ie start timestamp of the next date. I checked this code

datetime.date.today() + datetime.timedelta(days=1)

that gave me a hint to use timedelta or this one

from datetime import datetime
dt_obj = datetime.fromtimestamp(1140827600)
print("date_time:",dt_obj)

1140827600 was Saturday, February 25, 2006 12:33:20 AM, the next midnight will be February 26, 2006 00:00:00 AM. How can I get this date (in epoch) using only the value 1140827600?

fski51
  • 35
  • 4

1 Answers1

2

Set the hour, minute and second to 0 and add a day. Then convert it to a timestamp.

import datetime
dt_obj = datetime.datetime.fromtimestamp(1140827600)
print("date_time:",dt_obj)
(dt_obj.replace(hour=0, minute=0, second=0) + datetime.timedelta(days=1)).timestamp()
DeGo
  • 783
  • 6
  • 14