Exemplo n.º 1
0
        public static SyncTimeStampSource FromTicks(long ticks)
        {
            SyncTimeStampSource retv = new SyncTimeStampSource();

            retv.BaseTimeStamp = new DateTime(ticks, DateTimeKind.Utc);
            retv.Watch         = new Stopwatch();
            retv.Watch.Start();
            return(retv);
        }
Exemplo n.º 2
0
        public static SyncTimeStampSource FromLocalTime()
        {
            SyncTimeStampSource retv = new SyncTimeStampSource();

            retv.BaseTimeStamp = DateTime.UtcNow;
            retv.Watch         = new Stopwatch();
            retv.Watch.Start();
            return(retv);
        }
Exemplo n.º 3
0
        // GetUtcNetworkTime is based on stackoverflow.com/questions/1193955
        public static async Task <SyncTimeStampSource> FromNtpServer(string ntpServer)
        {
            SyncTimeStampSource retv         = new SyncTimeStampSource();
            Stopwatch           requestTimer = new Stopwatch();

            requestTimer.Start();
            retv.BaseTimeStamp = await Fi.Tech.GetUtcNetworkTime(ntpServer);

            requestTimer.Stop();
            retv.BaseTimeStamp.Subtract(TimeSpan.FromMilliseconds(requestTimer.ElapsedMilliseconds / 2));
            retv.Watch = new Stopwatch();
            retv.Watch.Start();
            return(retv);
        }