xbonez xbonez - 3 months ago 19
C# Question

Storing current time without milliseconds component

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?

Answer

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