/// <summary> ///get time status based on time/// </summary> /// <param name= "DT" ></param> /// <returns></returns> Public stringgettimeinfo (DateTime DT) {TimeSpan span= DateTime.Now-DT; if(span. Totaldays > -) { returndt. ToShortDateString (); } Else if(span. Totaldays > -) { return "1 months ago"; } Else if(span. Totaldays > -) { return "2 weeks ago"; } Else if(span. Totaldays >7) { return "1 weeks ago"; } Else if(span. Totaldays >1) { return string. Format ("{0} days ago", (int) Math.floor (span. Totaldays)); } Else if(span. TotalHours >1) { return string. Format ("{0} hours ago", (int) Math.floor (span. TotalHours)); } Else if(span. Totalminutes >1) { return string. Format ("{0} minutes ago", (int) Math.floor (span. totalminutes)); } Else if(span. TotalSeconds >=1) { return string. Format ("{0} seconds ago", (int) Math.floor (span. TotalSeconds)); } Else { return "just"; } }
Record, prevent forgetting!
C # Get time difference status