name: duk_components_to_time proto: | duk_double_t duk_components_to_time(duk_context *ctx, duk_time_components *comp); summary: |

Convert components (year, month, day, etc), interpreted in UTC, into a time value. The comp->weekday argument is ignored in the conversion. If the component values are invalid, an error is thrown.

There are some differences to the ECMAScript Date.UTC() built-in:

Like the ECMAScript primitives, the components can exceed their natural range and are normalized. For example, specifying comp->minutes as 120 is interpreted as adding 2 hours to the time value. The components are expressed as IEEE doubles to allow large and negative values to be used.

example: | duk_time_components comp; duk_double_t time; memset((void *) &comp, 0, sizeof(comp)); /* good practice even if fully initialized */ comp.year = 2016; comp.month = 0; /* 0-based, 1=January */ comp.day = 2; /* 1-based: second of January */ comp.hours = 3; comp.minutes = 4; comp.seconds = 5; comp.milliseconds = 6.0; /* allows sub-millisecond resolution */ comp.weekday = 0; /* ignored */ time = duk_components_to_time(ctx, &comp); printf("2016-01-02 03:04:05.006Z -> %lf\n", (double) time); tags: - time seealso: - duk_time_to_components introduced: 2.0.0