Pretty printing of DateTime values in C#
Asked Answered
M

2

5

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.

Minaret answered 6/11, 2008 at 12:9 Comment(0)
F
9

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()

Fpc answered 6/11, 2008 at 12:37 Comment(0)
B
0

http://msdn.microsoft.com/en-us/library/az4se3k1(VS.71).aspx should get you on your way,

Broddy answered 6/11, 2008 at 12:14 Comment(3)
That doesn't really match the power of datejs does it?Shopwindow
Actually, it does, assuming you already have a datetime value. What datejs does that this won't it parse input strings.Degauss
What David meant was that the Standard Format strings have only a few pre-canned formats, instead of the "build-your-own" style of datejs (and the Custom format strings)Fpc

© 2022 - 2024 — McMap. All rights reserved.