Getting Current Time As A Float C#

Is there a way of getting the current time as a float?

Don’t necessarily need the date as well, just the current time (I.E 8:00). I tried messing around with DateTime but either I’m not seeing a way to do it, or its not possible with DateTime!

Any help would be greatly appreciated!

Thanks in advance.

System.DateTime.Now should return the current time.

Edit: Realized that you want this as float. Depends on how you want the conversion. The way we represent time is not directly equivalent to one number, unless you want the time in Number of Seconds.

Probably something like;

((float)DateTime.Now.Hour + ((float)DateTime.Now.Minute * 0.01f))

That is actually pretty damn close to being perfect! It captured “11:2” and it was 11:21, so thats pretty awesome. Thank you very much!

1 Like

Why do you need it as a floating point value?

Game Analytics requires a float in their hooks to be sent to the server.

Could you use a long integer? There’s the Ticks property that will get you the exact DateTime in a single number. Seems simpler than dealing with converting from DateTime to float and back.
http://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx