Gmail date format

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from datetime import datetime,time
from django.utils.dateformat import DateFormat 

register = Library()

@register.filter
def humantime(t):
    now = datetime.now()
    if datetime.combine(now, time()) < t and t < datetime.combine(now + timedelta(1), time()):
        f = 'g:i a'
    elif now.year == t.year:
        f = 'M j'
    else:
        f = 'n/j/y'
    df = DateFormat(t)
    return df.format(f).replace('.m.', 'm')

More like this

  1. datemate by catellar 1 year, 9 months ago
  2. Coalesce for F() by axil 1 year, 3 months ago
  3. Take a django.core.mail email message and replace any MEDIA_URL-served images with attached images by agrossman@gmail.com 1 year, 4 months ago
  4. Confirm alert if the user navigates away without saving changes by mrazzari 3 years, 10 months ago
  5. Django Registration with GMail account by btbytes 6 years, 1 month ago

Comments

(Forgotten your password?)