[Solved] Return correct time measurements from a date [closed]


This is an overly simplified example of what you could do, using only .NET classes:

public static string TimeSinceEvent(DateTime eventTime)
{
    TimeSpan timeSince = DateTine.Now - eventTime;
    if (timeSince.Hours > 0)
        return string.Format("Added {0} hours ago", timeSince.Hours);
    else if (timeSince.Minutes > 0)
        return string.Format("Added {0} minutes ago", timeSince.Minutes);
    else 
        return string.Format("Added {0} seconds ago", timeSince.Seconds);
}

Of course, you could add more cases to handle days, months, etc.

1

solved Return correct time measurements from a date [closed]