public String FriendlyFormatFromNow(DateTime date)
{
TimeSpan now = new TimeSpan(DateTime.Now.Ticks);
TimeSpan cur = new TimeSpan(date.Ticks);
TimeSpan diff = now.Subtract(cur);
if (diff.TotalSeconds == 0)
{
return "Just now";
}
if (diff.Days == 0)
{
if (diff.Hours == 0)
{
if (diff.Minutes == 0)
{
return String.Format("{0} second{1} ago",
diff.Seconds, diff.Seconds > 1 ? "s" : String.Empty);
}
else
{
return String.Format("{0} minute{1} ago",
diff.Minutes, diff.Minutes > 1 ? "s" : String.Empty);
}
}
else
{
return String.Format("{0} hour{1} ago",
diff.Hours, diff.Hours > 1 ? "s" : String.Empty);
}
}
else
{
return String.Format("{0} day{1} ago",
diff.Days, diff.Days > 1 ? "s" : String.Empty);
}
}