Login

Tag "now"

Snippet List

humanize time difference (how long ago)

If you ever have a need to display something like: "last update 5 days ago" "user logged in 2 mins ago" you can use this script to determine how long ago a timestamp is versus now().

  • time
  • now
  • humanize
Read More

Client-side Django-style date & time string formatting

This is a reasonably straight forward port of functionality provided by the `django.utils.dateformat` module into a method extending JavaScript's Date object. Its intended use is to allow client-side dynamic content to share the same date & time string formatting as Django template markup. By using this in conjunction with a context processor (to pass a format string to all templates) you can switch formats for both server-generated & client-generated dates across a complete site with a single setting. The function supports *almost* the entire format -- as listed by the Django documentation for the [now template tag](http://www.djangoproject.com/documentation/templates/#now) -- with the exception of "I" & "T". As a 'dumb' illustration, the following template tag usage: It is {% now "jS F Y H:i" %} ...could equate to the following: It is <script type="text/javascript">var now = new Date(); document.write(now.strfdate('jS F Y H:i'));</script> It's not extensively tested (I only wrote it over the weekend), but seems to be working okay. Feel free to leave any corrections or suggestions in the comments, and I'll try to keep this entry updated if I make any fixes or changes.

  • javascript
  • dynamic
  • datetime
  • date
  • format
  • time
  • string
  • now
Read More

3 snippets posted so far.