name: duk_time_to_components proto: | void duk_time_to_components(duk_context *ctx, duk_double_t time, duk_time_components *comp); summary: |

Convert a time value to components (year, month, day, etc) interpreted in UTC. If the time value is invalid, e.g. beyond the valid ECMAScript time range, an error is thrown.

There are some differences to the ECMAScript Date UTC accessors like Date.prototype.getUTCMinutes():

example: | duk_double_t time = 1451703845006.0; /* 2016-01-02 03:04:05.006Z */ duk_time_components comp; const char *weekdays[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; /* Note that month is zero-based to match the ECMAScript API, so for * human readable printing add 1 to the month. Time components are * IEEE doubles to match ECMAScript Date behavior. */ duk_time_to_components(ctx, time, &comp); printf("Datetime: %04d-%02d-%02d %02d:%02d:%02d.%03dZ\n", (int) comp.year, (int) comp.month + 1, (int) comp.day, (int) comp.hours, (int) comp.minutes, (int) comp.seconds, (int) comp.milliseconds); printf("Weekday is: %s\n", weekdays[(int) comp.weekday]); /* 0=Sunday */ tags: - time seealso: - duk_components_to_time introduced: 2.0.0