Hari Addepalli
Hari Addepalli

Reputation: 3

use closing hours by default

Using this piece of the pytz script,

import dateutil
import pytz

utc = pytz.UTC
print(utc.localize(dateutil.parser.parse('2024-10-31')))

the output shows:

2024-10-31 00:00:00+00:00

We want to default to "closing" hours or end of the day, i.e 2024-10-31 23:59:59+00:00 in the example. Is there a way to do it?

Upvotes: 0

Views: 30

Answers (1)

Pete M
Pete M

Reputation: 194

datetime.timedelta is useful for this type of thing:

import dateutil
import pytz
from datetime import timedelta
utc = pytz.UTC
print(utc.localize(dateutil.parser.parse('2024-10-31'))+timedelta(days=1)-timedelta(seconds=1))

Upvotes: 0

Related Questions