time-precision

Function that creates a timestamp in c#

梦想与她 提交于 2019-11-27 06:13:28
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 this value in a database agnostic way so i can sortby it later and find out which value is greater from another etc. I always use something like the following: public static String GetTimestamp(this DateTime value) { return value.ToString("yyyyMMddHHmmssfff"); } This will give you a string like 200905211035131468, as the string goes from highest order

How precise is the internal clock of a modern PC?

别等时光非礼了梦想. 提交于 2019-11-27 04:33:23
问题 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 actual nanoseconds. However, usual frameworks still return time with a precision of only around 15ms. My question is, which steps did increase the precision, how is it possible to measure in nanoseconds, and why are we still often getting less-than-microsecond precision

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

余生长醉 提交于 2019-11-26 18:27:42
问题 So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead? 回答1: Achieve microsecond accuracy in most browsers using: window.performance.now() See also: https://developer.mozilla.org/en-US/docs/Web/API/Performance.now() http://www.w3.org/TR/hr-time/ 回答2: Building on Jeffery's answer, to get an absolute time-stamp (as the OP wanted) the code would be: var TS = window.performance.timing.navigationStart + window

Parsing datetime strings containing nanoseconds

不羁的心 提交于 2019-11-26 13:50:55
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 %f. Do the Python datetime and time modules really not support nanoseconds? Dougal You can see from the source that datetime objects don't support anything more fine than microseconds. As pointed out by Mike Pennington in the comments, this is because actual hardware clocks aren't nearly that precise . Wikipedia says that HPET has frequency "at

Function that creates a timestamp in c#

梦想的初衷 提交于 2019-11-26 12:52:38
问题 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 this value in a database agnostic way so i can sortby it later and find out which value is greater from another etc. 回答1: I always use something like the following: public static String GetTimestamp(this DateTime value) { return value.ToString(

Parsing datetime strings containing nanoseconds

那年仲夏 提交于 2019-11-26 02:01:52
问题 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 %f. Do the Python datetime and time modules really not support nanoseconds? 回答1: You can see from the source that datetime objects don't support anything more fine than microseconds. As pointed out by Mike Pennington in the comments, this is

How to measure time in milliseconds using ANSI C?

◇◆丶佛笑我妖孽 提交于 2019-11-26 01:37:32
问题 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. 回答1: There is no ANSI C function that provides better than 1 second time resolution but the POSIX function gettimeofday provides microsecond resolution. The clock function only measures the amount of time that a process has spent executing and is not accurate on many systems. You can use this function like this: struct timeval tval_before,

C# DateTime.Now precision

不羁的心 提交于 2019-11-26 00:43:44
问题 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, rather than capturing more precise millisecond increments. I know there is a Stopwatch class that would be better suited for doing precise time measurements, but I was curious if someone could explain this behavior in DateTime? Is there an official

System.currentTimeMillis vs System.nanoTime

﹥>﹥吖頭↗ 提交于 2019-11-25 22:21:39
问题 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 last call and I want to be as precise as possible. I\'ve read that there are some serious time-resolution issues between different operating systems (namely that Mac / Linux have an almost 1 ms resolution while Windows has a 50ms resolution??). I\