3

I'm aware of various Windows command line functions, such as:

TIME - allows you to get and set the clock time

wmic os get localdatetime - returns local datetime

wmic os get lastbootuptime - gets the last boot up time in ticks (I haven't found the command line for getting the number of ticks)

What does JavaScript use to get the time when you do the following?

var d = new Date();
var time = d.getTime();

Is it a system call, and if so which one? And how accurate is it?

Matt
  • 303
  • 1
  • 2
  • 16
  • 1
    "Javascript" is a language. You can ask that question about any given implementation. And they're all open-source, so you can find out. – SLaks Mar 27 '16 at 01:24
  • The accuracy is not specified in the specification. – user2864740 Mar 27 '16 at 01:27
  • *"And how accurate is it?"* - Why would it *not* be accurate? I mean, it should be obvious that JS can't tell if the device's system clock is set to the wrong time, but why would you worry that JS wouldn't accurately report the system clock's time? – nnnnnn Mar 27 '16 at 01:28
  • @nnnnnn "*How* accurate is it?" not, "Is it reasonably accurate?". (Where 'reasonably' may change depending on the [mis]use of such.) – user2864740 Mar 27 '16 at 01:28
  • Anyway, FWIW, I would reasonably expect a ~15ms resolution or 1/66s accuracy as a 'bottom denominator'. YMMV across all implementations ~ not to mention devices. Also see http://stackoverflow.com/questions/6233927/microsecond-timing-in-javascript (talks about the high-resolution timer API) – user2864740 Mar 27 '16 at 01:35

1 Answers1

2

This is related to JS not a specific OS:

The JavaScript Date object provides uniform behavior across platforms. The time value can be passed between systems to represent the same moment in time and if used to create a local date object, will reflect the local equivalent of the time.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

omarjmh
  • 13,632
  • 6
  • 34
  • 42
  • 1
    I believe the OP is (at least partly) looking for the 'details', which is specific to the particular *implementation*. Not sure why the "boot up time" bit was included in the question.. – user2864740 Mar 27 '16 at 01:27
  • Yes, I'm asking for the particular implementation, not the API output behavior of JavaScript date. As for the "boot up time", bit I should probably clarify that. I was listing example command prompts to try to encourage an answer about Windows-specific function calls that are made to get local time. If there are any. – Matt Mar 27 '16 at 01:49