Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty printing of DateTime values in C#

I'm hoping that someone has found a way of doing this already or that there is a library already in existence. It's one of those things that would be nice but is in no way necessary for the time being.

The functionality I'm looking for is something like datejs in reverse.

Thanks,

Simon.


Thanks, using something like the dddd example might be a good start towards usability. The more I think about this problem the more it depends on the values being used. I'm specifically dealing with a series of timestamped versions of a document so there is a good chance that they will be clustered. Today isn't so hot if you have saved it three times in the last five minutes.

If I come up with something I'll share it with the community.

like image 694
Simon Farrow Avatar asked Nov 06 '08 12:11

Simon Farrow


1 Answers

Actually, what you really want is the Custom DateTime Format strings: http://msdn.microsoft.com/en-us/library/8kb3ddd4(VS.71).aspx

DateTime.Now.ToString("ggyyyy$dd-MMM (dddd)")

will return "A.D.2008$06-Nov (Thursday)" if that's what you want.

And to get something closr to datejs ("in forward"), you can use the same strings in DateTime.ParseExact()

like image 152
James Curran Avatar answered Sep 17 '22 00:09

James Curran