Delivery times are augmented by how Stackoverflow and Facebook do - C #

I have an ASP.NET MVC 2 application that I create, and users are allowed to publish data in specific sections. I would like to show "Added to" in the same format as Stackoverflow and Facebook.

i.e. On this site, when I post this question, it will display “asked 3 seconds ago,” then “asked 3 minutes ago,” and a few days later it will display the date.

My application is C # if someone can point me in the right direction in order to best accomplish this, which would be great!

+4
source share
2 answers

Take a look at the jQuery timeago plugin . I use it on the site that I create and it works great.

+7
source

In C #, it looks mostly like this. Another answer is javascript, but that doesn't seem to be your question.

DateTime now = DateTime.UtcNow; DateTime postedAt = new DateTime(); var age = now.Subtract(postedAt); if (age < new TimeSpan(0, 1, 0)) return (((int)age.TotalSeconds).ToString() + " seconds ago"); else if (age < new TimeSpan(1, 0, 0)) return (((int)age.TotalMinutes).ToString() + " minutes ago"); else if (age < new TimeSpan(24, 0, 0)) return (((int)age.TotalHours).ToString() + " hours ago"); else return (((int)age.TotalDays).ToString() + " days ago"); 
+2
source

All Articles