xbonez xbonez - 4 months ago 24
C# Question

Storing current time without milliseconds component

I have a timespan object that needs to hold only time, without date. I would use


but the problem is it gives time in the format


I don't want the milliseconds component. How can I trim it out?


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