1 2 3 4 5 6 7 8 9 10 11 | @register.simple_tag
def time_of_day():
import datetime, pytz
from django.conf import settings
cur_time = datetime.datetime.now(tz=pytz.timezone(str(settings.TIME_ZONE)))
if cur_time.hour < 12:
return 'Morning'
elif 12 <= cur_time.hour < 18:
return 'Afternoon'
else:
return 'Evening'
|
More like this
- UTC-based astimezone filter by miracle2k 7 months ago
- astimezone template tag by whardier 1 year, 2 months ago
- Template tags for localizing UTC times with pytz by wolever 9 months, 1 week ago
- filter dates to user profile's timezone by Scanner 5 years, 1 month ago
- UTC DateTime field by ludo 4 years, 9 months ago
Comments