Last active
August 29, 2015 14:08
-
-
Save k4ml/2f6bf5ee5d1f835ad64b to your computer and use it in GitHub Desktop.
django local date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
# output: Selasa, 21 Oktober 2014, 08:30 pagi. | |
DAYS = { | |
6: 'Ahad', | |
0: 'Isnin', | |
1: 'Selasa', | |
2: 'Rabu', | |
3: 'Khamis', | |
4: 'Jumaat', | |
5: 'Sabtu', | |
} | |
MONTHS = { | |
1: 'Januari', | |
2: 'Februari', | |
3: 'Mac', | |
4: 'April', | |
5: 'Mei', | |
6: 'Jun', | |
7: 'Julai', | |
8: 'Ogos', | |
9: 'September', | |
10: 'Oktober', | |
11: 'November', | |
12: 'Disember', | |
} | |
@register.filter | |
def date_my(value): | |
if value.hour < 12: | |
ampm = 'pagi' | |
elif value.hour > 12 and value.hour < 18: | |
ampm = 'petang' | |
else: | |
ampm = 'malam' | |
date_str = '%s, %s %s %s, %s %s' % (DAYS[value.weekday()], value.day, MONTHS[value.month], value.year, value.strftime('%I:%M'), ampm) | |
return date_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment