欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获得当前时间的总毫秒数

程序员文章站 2022-06-21 10:37:34
...

代码

using System;
DateTime d = DateTime.Now;
TimeSpan ts = new TimeSpan(d.Ticks);
double startTime = ts.TotalMilliseconds;  //获得当前时间的总毫秒数.

使用案例

void OnGUI(){
    if (GUI.Button(new Rect(0,0,200,100),"find")) {
        DateTime d = DateTime.Now;
        TimeSpan ts = new TimeSpan(d.Ticks);
        double startTime = ts.TotalMilliseconds;  //获得当前时间的总毫秒数.
        GameObject obj = GameObject.Find("GameObject (" + num +")");
        num++;
        d = DateTime.Now;
        ts = new TimeSpan(d.Ticks);
        double endTime = ts.TotalMilliseconds;
        msg = "time(ms):" + (endTime - startTime) + " obj:" + obj.name;
    }
    if (GUI.Button (new Rect (0, 100, 300, 300), msg)) {

    }
}