Search code examples
jqueryhtmlasp.net-mvctimeago

Timeago.js - Title can't be changed?


I am using an HTML Helper to generate the Timestamp.js tags <abbr>

public static MvcHtmlString TimeAgo(this HtmlHelper html,
                            DateTime dateTime)
{
    var tagBuilder = new TagBuilder("abbr");
    tagBuilder.SetInnerText(String.Format("{0:MMMM d, yyyy}", dateTime));
    tagBuilder.AddCssClass("timeago");
    tagBuilder.Attributes.Add("title", String.Format("{0:s}Z", dateTime));            
    return MvcHtmlString.Create(tagBuilder.ToString());
}

The following is generated :

<abbr class="timeago" title="July 2, 2014">6 minutes ago</abbr>

It's ok, except that I would like to have a full datetime on the title tag, since I found it more useful for the end users.

Is it possible?

Thanks a lot friends,


Solution

  • You just have to change the format in here:

    tagBuilder.SetInnerText(String.Format("{0:MMMM d, yyyy}", dateTime));
    

    for example if you need something like: 2014-07-02 you should write yyyy-MM-dd

    Here you can find every possible format!