I am using DateTime.Now.ToString() in a windows service and it is giving me output like "7/23/2010 12:35:07 PM " I want to exclude the second part, displaying only up to minute.
So how to exclude seconds from that format...?
Output it as short date pattern:
DateTime.Now.ToString("g")
See MSDN for full documentation.
You need to pass in a format string to the ToString()
function:
DateTime.Now.ToString("g")
This option is culture aware.
For this kind of output you could also use a custom format string, if you want full control:
DateTime.Now.ToString("MM/dd/yyyy hh:mm")
This will output exactly the same regardless of culture.
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