I have a timespan object that needs to hold only time, without date. I would use
DateTime.Now.TimeOfDay
but the problem is it gives time in the format
15:51:51.7368329
I don't want the milliseconds component. How can I trim it out?
Use the setSeconds() method to remove the seconds and milliseconds from a date, e.g. date. setSeconds(0, 0) . The setSeconds method takes the seconds and milliseconds as parameters and sets the provided values on the date. Copied!
Solution 1 Using different methods on the DateTime, like . Today give the date part, but the other parts of it are zero. This is by design. If you don't want to display the seconds when you create the string, use a format string, like MM/dd/yyyy hh.mm and leave the tt part off.
You can either use DateTime.Now.Hour/Minute/Second
properties or you could use DateTime.Now.ToString("HH:mm:ss")
.
Refer here for more info: http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
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