How to Convert DateTime Now

I have an entrance 15:20:30

I want to convert to seconds.

+4
source share
3 answers

Seeing that you did not ask the question correctly, I interpreted it as representing 15 hours 20 minutes and 30 seconds, unlike DateTime.Now. (Obviously, this is the same as "How many seconds since midnight")

TimeSpan MySpan = new TimeSpan(15, 20, 30); MySpan.TotalSeconds; 

Although, if you want only seconds from the current DateTime.Now (these are not TotalSeconds, but only the current minutes of seconds), just use:

  DateTime.Now.Second 
+24
source
 var dt = DateTime.Now; var ticks = dt.Ticks; var seconds = ticks/TimeSpan.TicksPerSecond; 

Each tick is equal to 100 nanoseconds.

+10
source

Not sure what you really want, but if you want to calculate the number of seconds from 15 hours, 20 minutes and 30 seconds, you can do this:

 Int32 GetSeconds(Int32 hours, Int32 minutes, Int32 seconds) { return ((hours*60) + minutes)*60 + seconds; } 
+4
source

All Articles