Displaying time in relative format
Thursday, August 28th, 2008Many websites specially forum sites display time relative to the current time as “3 Hours 25 Minutes ago”, “30 Seconds ago” etc. In this post I will show a method using which we can convert datetime into descriptive relative time string.
The method takes 2 parameters 1. the time to process, 2. the time to which the output will be relative. Usually it is DateTime.UtcNow. There is also an overload which only takes the time to process where the second parameter defaults to DateTime.UtcNow. Let us see some sample output of this function.