c#获取当前时间的毫秒数
To get the milliseconds only of the current time, we use the "Millisecond" property of the DateTime class in C#. We use the "Millisecond" property with the object of DateTime class which should be initialized with the current date-time i.e. "Now". The property returns an integer value that is the milliseconds value of the current time.
为了仅获取当前时间的毫秒数 ,我们在C#中使用DateTime类的“ Millisecond”属性 。 我们对DateTime类的对象使用“ Millisecond”属性 ,该对象应使用当前日期时间(即“ Now”)初始化。 该属性返回一个整数值,该整数值是当前时间的毫秒值。
Syntax:
句法:
int DateTime.Millisecond;
This property returns an integer value.
此属性返回一个整数值。
C# code to get milliseconds only from the current time
C#代码仅从当前时间获取毫秒
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
翻译自: https://www.includehelp.com/dot-net/get-milliseconds-of-the-current-time-in-csharp.aspx
c#获取当前时间的毫秒数