sunil sunil - 1 year ago 87
Javascript Question

Which plugin used by gmail to show mail time or date?

I wanted to know that which js plugin used by gmail to show mail time(if today's mail) or date.

If mail received today itself then it shows time '1:18 pm' otherwise date like 'sep 5'. And if mail was received i last year then it showing date like '11/12/13'.

Is there any js plugin or rails to do that ?
Like this enter image description here


Answer Source

why you need any plugin or gem for this. You can easily do it with helper. In your helper :

require 'date'

def time_date(date)
  if date.year >
    date.to_date == ? date.strftime('%l:%M %P') : date.strftime('%b %d')

in your view :

<%= time_date(@model.created_at) %>

As per your comment You do want to use jquery to show datetime instead of helper. So there is no direct plugin for this. But you can use this to achieve what you want.

Lets consider on your view you have following div:

<div class="start">2014/09/11 09:00:03</div>

Now use jquery.formatDateTime to format div date :

  var datetime = new Date($('.start').text());
  var today = new Date();
  if(today.getFullYear() > datetime.getFullYear()){
    if(today.getDate() > datetime.getDate()){
      $('.start').formatDateTime('M m');
      $('.start').formatDateTime('g:ii a');


Hope this help you!