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
- astimezone template tag by whardier 2 years, 2 months ago
- Template tags for localizing UTC times with pytz by wolever 1 year, 9 months ago
- filter dates to user profile's timezone by Scanner 6 years, 1 month ago
- UTC-based astimezone filter by miracle2k 1 year, 6 months ago
- UTC DateTime field by ludo 5 years, 8 months ago
Comments