In Javascript I can use var d = new Date();
    var n = d.getTime(); to get the time in milliseconds. Is there any similar method in C#?
            Asked
            
        
        
            Active
            
        
            Viewed 447 times
        
    -4
            
            
        
        Alok Verma
        
- 1
 - 1
 
1 Answers
5
            
            
        Subtracting a DateTime from another DateTime returns a TimeSpan.
DateTime d1 = DateTime.UtcNow;
DateTime d2 = DateTime.UtcNow.AddDays(1);
TimeSpan ts = d2 - d1;
Console.WriteLine(ts.TotalMilliseconds);
// Outputs 86400000
        ProgrammingLlama
        
- 36,677
 - 7
 - 67
 - 86