How to convert one datetime to ticks?
+4
A:
By using the Ticks property:
var now = DateTime.Now;
var ticks = now.Ticks;
UPDATE:
For those who don't like the var
keyword and consider this more readable:
DateTime now = DateTime.Now;
long ticks = now.Ticks;
Darin Dimitrov
2010-05-23 08:47:21
You are overusing the `var` keyword. It's not obvious what type the `Ticks` property returns, especially for someone who has never seen it before...
Guffa
2010-05-23 09:06:50
@Guffa, I agree. I believe using var in this example actually harms readability.
David Neale
2010-05-23 09:18:01
OK, I replace the `var` keyword with proper types.
Darin Dimitrov
2010-05-23 09:23:54
Or simply: long ticks = DateTime.Now.Ticks;
rursw1
2010-05-23 09:33:16
@rursw1: Then it's just an example on how to convert the current time to ticks. By giving the example as two lines, the second line is an example of how to convert any datetime value.
Guffa
2010-05-23 17:29:43