c#获取当前时间的毫秒数_在C#中获取当前时间的毫秒数

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#获取当前时间的毫秒数

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值