AjaxControlToolkit.Twitter.Ago C# (CSharp) Method

Ago() public static method

public static Ago ( System.DateTime date ) : string
date System.DateTime
return string
        public static string Ago(DateTime date)
        {
            var timeSpan = DateTime.Now - date;
            if (timeSpan.TotalMinutes < 1)
                return "Less than a minute ago";
            else if (Math.Round(timeSpan.TotalHours) < 2)
                return String.Format("{0} minutes ago", Math.Round(timeSpan.TotalMinutes));
            else if (Math.Round(timeSpan.TotalDays) < 2)
                return String.Format("{0} hours ago", Math.Round(timeSpan.TotalHours));
            else
                return String.Format("{0} days ago", Math.Round(timeSpan.TotalDays));
        }

Usage Example

示例#1
0
            private void ctlStatus_DataBind(object sender, EventArgs e)
            {
                // set the Text property of the Label to the TotalPostCount property
                var ctlStatus = (LiteralControl)sender;
                var container = (ListViewDataItem)ctlStatus.NamingContainer;
                var status    = ((TwitterStatus)container.DataItem);

                ctlStatus.Text = String.Format(
                    "<li>{0}<br /><span class=\"ajax__twitter_createat\">{1}</span></li>",
                    Twitter.ActivateLinks(status.Text),
                    Twitter.Ago(status.CreatedAt)
                    );
            }
All Usage Examples Of AjaxControlToolkit.Twitter::Ago