Date and time

Date and time handling is often a portability issue when adapting Duktape to more exotic environments. The duk_config.h configuration header selects platform specific providers needed to implement the Date built-in. Duktape has built-in providers for mainstream platforms (Linux, Windows, OS X) which should usually work without changes. You can also write an external Date provider for more exotic environments. An external Date provider can also be used e.g. when a time offset needs to be applied to the platform time, or when using time virtualization.

ECMAScript code interacts with date/time through the standard Date built-in which is, by specification, limited to millisecond resolution. There are currently no Duktape specific ECMAScript date/time APIs. (A custom API may be added later to deal with sub-millisecond resolution.)

C code can of course use platform date/time APIs directly, but the Duktape C API also provides date/time API calls. These calls see the same time values as ECMAScript code which may matter when e.g. time virtualization is used. Using these calls makes your code platform neutral and thus more portable. The Duktape C API allows sub-millisecond resolution for time values. See How to work with time values for more details.