![]() |
| ||
| Calculate "time ago" - time that passed since a DateTime I've been searching like crazy for this but can't find anything in C#/VB.NET. I want to show off a DateTime as a "x days x hours x minutes x seconds ago" string, so I'm looking for a function that calculates the time difference between a DateTime and the current date and time, and shows it in that nice string that you can see everywhere around the web these days. Preferably something like what geekpedia.com has on its frontpage. Note that it always shows the two most relevant time objects at once. For example for the newer posting it shows "17 hours, 31 minutes ago" and for the older ones it shows "3 days, 19 hours ago" -- it doesn't keep showing minutes, seconds, unless relevant. If anyone happens to have a C#/VB.NET function for this, it will be much appreciated. Thanks! |
| ||
| Re: Calculate "time ago" - time that passed since a DateTime Here you are static void Main(string[] args) |
| ||
| Re: Calculate "time ago" - time that passed since a DateTime Thanks a lot! This code is so much simpler than similar functions I've seen for other languages (such as PHP.) Guess we owe it to the versatility of the DateTime class. |
| ||
| Re: Calculate "time ago" - time that passed since a DateTime You're welcome, hope it helped! Please mark your thread solved if it been. |
| All times are GMT -4. The time now is 7:38 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC