Syntax-
int DateTime.Millisecond;
C# code to get milliseconds only from the current time
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//creating an object of DateTime class
//and, initializing it with the current time
//using "Now"
DateTime dt = DateTime.Now;
//getting Milliseconds only from the currenttime
int ms = dt.Millisecond;
//printing the current date & time
Console.WriteLine("The current time is: " + dt.ToString());
//printing the Milliseconds value of the current time
Console.WriteLine("Milliseconds of current time: " + ms.ToString());
//just to print a new line
Console.WriteLine();
}
}
}
Output–
RUN 1:
The current time is: 10/17/2019 1:09:19 PM
Milliseconds of current time: 742
RUN 2:
The current time is: 10/17/2019 1:10:23 PM
Milliseconds of current time: 781