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 3 months, 1 week ago
- astimezone template tag by whardier 11 months ago
- Template tags for localizing UTC times with pytz by wolever 5 months, 2 weeks ago
- filter dates to user profile's timezone by Scanner 4 years, 9 months ago
- UTC DateTime field by ludo 4 years, 5 months ago
Comments