Questions tagged [time-precision]

35 questions
415
votes
10 answers

System.currentTimeMillis vs System.nanoTime

Accuracy Vs. Precision What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime() when updating my object's positions in my game? Their change in movement is directly proportional to the elapsed time since the…
mmcdole
  • 91,488
  • 60
  • 186
  • 222
172
votes
10 answers

Get time in milliseconds using C#

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 second ago. I've tried converting DateTime.Now to a TimeSpan and getting…
Entity
  • 7,972
  • 21
  • 79
  • 122
156
votes
9 answers

How to measure time in milliseconds using ANSI C?

Using only ANSI C, is there any way to measure time with milliseconds precision or more? I was browsing time.h but I only found second precision functions.
corto
  • 2,657
  • 4
  • 21
  • 9
108
votes
7 answers

C# DateTime.Now precision

I just ran into some unexpected behavior with DateTime.UtcNow while doing some unit tests. It appears that when you call DateTime.Now/UtcNow in rapid succession, it seems to give you back the same value for a longer-than-expected interval of time,…
Andy White
  • 86,444
  • 48
  • 176
  • 211
102
votes
6 answers

Function that creates a timestamp in c#

I was wondering, is there a way to create a timestamp in c# from a datetime? I need a millisecond precision value that also works in Compact Framework(saying that since DateTime.ToBinary() does not exist in CF). My problem is that i want to store…
81
votes
7 answers

Is there any way to get current time in nanoseconds using JavaScript?

So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead?
Carlos Melo
  • 3,052
  • 3
  • 37
  • 45
53
votes
6 answers

Parsing datetime strings containing nanoseconds

I have some log files with times in the format HH:MM::SS.nano_seconds (e.g. 01:02:03.123456789). I would like to create a datetime in python so I can neatly do math on the time (e.g. take time differences). strptime works well for microseconds using…
user1332148
  • 1,256
  • 2
  • 11
  • 24
34
votes
3 answers

How precise is the internal clock of a modern PC?

I know that 10 years ago, typical clock precision equaled a system-tick, which was in the range of 10-30ms. Over the past years, precision was increased in multiple steps. Nowadays, there are ways to measure time intervals in nanoseconds. However,…
mafu
  • 31,798
  • 42
  • 154
  • 247
25
votes
10 answers

How can I get the Windows system time with millisecond resolution?

How can I get the Windows system time with millisecond resolution? If the above is not possible, then how can I get the operating system start time? I would like to use this value together with timeGetTime() in order to compute a system time with…
10
votes
3 answers

Storing microseconds in MySQL: which workaround?

we're writing a scientific tool with MySQL support. The problem is, we need microsecond precision for our datetime fields, which MySQL doesn't currently support. I see at least two workarounds here: Using a decimal() column type, with integer part…
dpq
  • 9,028
  • 10
  • 49
  • 69
10
votes
2 answers

Java ScheduledExecutorService BAD Precision

Hi there I wrote a simple program to test the precision of the ScduledExecutorService.schedule() function. The test sets a delay and checks the effective waited time. The test have been performed on a i7 machine running Linux 3.8 x86_64, with both…
snovelli
  • 5,804
  • 2
  • 37
  • 50
8
votes
1 answer

DateTimeOffset resolution in c# and SQL Server

Docs state that in both .NET and SQL server the resolution is 100ns. The time component of a DateTimeOffset value is measured in 100-nanosecond units called ticks - C# Accuracy - 100 nanoseconds - SQL Server However SQL seems to drop the last digit…
Evgeni
  • 3,341
  • 7
  • 37
  • 64
8
votes
2 answers

MySQL Join/Comparison on a DATETIME column (<5.6.4 and > 5.6.4)

Suppose i have two tables like so: Events ID (PK int autoInc), Time (datetime), Caption (varchar) Position ID (PK int autoinc), Time (datetime), Easting (float), Northing (float) Is it safe to, for example, list all the events and their position…
Simon
  • 9,197
  • 13
  • 72
  • 115
5
votes
4 answers

Comparing System.nanoTime() values resulting from different machines

Is it correct to compare two values resulting from a call to System.nanoTime() on two different machines? I would say no because System.nanoTime() returns a nanosecond-precise time relative to some arbitrary point time by using the Time Stamp…
Laurent
  • 14,122
  • 13
  • 57
  • 89
4
votes
1 answer

threading.Timer time precision

What does the time accuracy of Python's threading.Timer depend on? Does it depend on the OS used? Does it depend on the Python implementation used? Does it depend on the interval? How can it be benchmarked? Are there already benchmarks out there?
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
1
2 3