Get time in milliseconds using C#

后端 未结 8 1699
你的背包
你的背包 2021-01-30 09:56

I\'m making a program in which I need to get the time in milliseconds. By time, I mean a number that is never equal to itself, and is always 1000 numbers bigger than it was a se

8条回答
  •  悲&欢浪女
    2021-01-30 10:18

    I use the following class. I found it on the Internet once, postulated to be the best NOW().

    /// Class to get current timestamp with enough precision
    static class CurrentMillis
    {
        private static readonly DateTime Jan1St1970 = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        /// Get extra long current timestamp
        public static long Millis { get { return (long)((DateTime.UtcNow - Jan1St1970).TotalMilliseconds); } }
    }
    

    Source unknown.

提交回复
热议问题