在C#中获取当前时间的毫秒数
为了仅获取当前时间的毫秒数,我们使用C#中DateTime类的“Millisecond”属性。我们对DateTime类的对象使用“Millisecond”属性,该对象应使用当前日期时间即“Now”进行初始化。该属性返回一个整数值,该整数值是当前时间的毫秒值。
语法:
int DateTime.Millisecond;
此属性返回一个整数值。
C#代码仅从当前时间获取毫秒
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//创建DateTime类的对象
//然后用当前时间进行初始化
//使用“现在”"Now"
DateTime dt = DateTime.Now;
//仅从当前时间获得毫秒
int ms = dt.Millisecond;
//printing the current date & time
Console.WriteLine("The current time is: " + dt.ToString());
//打印当前时间的毫秒值
Console.WriteLine("Milliseconds of current time: " + ms.ToString());
//只是打印新行
Console.WriteLine();
}
}
}输出结果
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
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短