|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
C# / VB.NET code which takes a datetime in as parameter and returns a stringI am wondering if someone know where I can find some code which takes a datetime as a parameter and returns a string like many of the forums example of some return strings.. 2 seconds ago 3 minutes ago 3 minutes and 20 seconds ago 4 hours 3 minutes ago 3 days ago ..... ..... 06/01/2009 C# http://www.hd720i.com/Category/CSharp/16-1.aspx VB.NET http://www.hd720i.com/Category/Visual%20Basic/27-1.aspx "Nully Girl" <nullyg***@hotmail.com> wrote in message public string StringFromDate(DateTime MyDateTime)news:O3b2hCZ9JHA.4376@TK2MSFTNGP04.phx.gbl... > I am wondering if someone know where I can find some code which takes a > datetime as a parameter and returns a string like many of the forums > example of some return strings.. { string MyString = String.Empty; // do some processing on MyDateTime; return MyString } > C# Is this a genuine question, or are you just spamming the Microsoft > http://www > > VB.NET > http://www Technology People website...?
Show quote
Hide quote
"Nully Girl" wrote: There may be a package already written to do this, but you could do:> Hi, > > I am wondering if someone know where I can find some code which takes a > datetime as a parameter and returns a string like many of the forums > example of some return strings.. > > 2 seconds ago > 3 minutes ago > 3 minutes and 20 seconds ago > 4 hours 3 minutes ago > 3 days ago > ..... > ..... > 06/01/2009 > > > C# > http://www.hd720i.com/Category/CSharp/16-1.aspx > > VB.NET > http://www.hd720i.com/Category/Visual%20Basic/27-1.aspx > > > > > string ElapsedTime(DateTime basetime) { string when; TimeSpan ts; DateTime t = DateTime.Now; if (basetime < t) { when = "ago"; ts = t.Subtract(basetime); } else { when = "from now"; ts = basetime.Subtract(t); } if (ts.Days > 0) return string.Format("{0} days {1} hours {2}", ts.Days, ts.Hours, when); else if (ts.Hours > 0) return string.Format("{0} hours {1} minutes {2}", ts.Hours, ts.Minutes, when); // etc... }
Other interesting topics
Disable Validation For Dynamically Created Control
Multiple Drop-Downs ASP.NET System.OutOfMemoryException <forms loginUrl="https:// pb too many forms, what should I do? MSDN help for MVC Value cannot be null. Parameter name: type Permissions on new Text File - IIS6 and Windows authentication. LinkButton fails in Firefox *The ASP.NET requires .NET Framework 1.1 from Microsoft. |
|||||||||||||||||||||||