I'm working on formatting datetime's to display on a graph, and its working great so far. I have the format string:
M/dd/yyyy HH:mm:ss
and it prints as I'd like it to except the following: I want to completely hide the HH:mm:ss if the time is midnight.
Is it possible to do without a custom iformatprovider?
Thanks!
DateTime time = DateTime.Now;
string txt = time.ToString(time == time.Date ? "M/dd/yyyy" : "M/dd/yyyy HH:mm:ss");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With