You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

name: duk_time_to_components
proto: |
void duk_time_to_components(duk_context *ctx, duk_double_t time, duk_time_components *comp);
summary: |
<p>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.</p>
<p>There are some differences to the Ecmascript <code>Date</code> UTC
accessors like <code>Date.prototype.getUTCMinutes()</code>:</p>
<ul>
<li>The month component is one-based, not zero-based.</li>
<li>The time value is allowed to have fractions (sub-millisecond
resolution) so that the millisecond component may also have
fractions.</li>
</ul>
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"
};
duk_time_components(ctx, time, &comp);
printf("Datetime: %04d-%02d-%02d %02d:%02d:%02d.%03dZ\n",
(int) comp.year, (int) comp.month, (int) comp.day,
(int) comp.hour, (int) comp.minute, (int) comp.second,
(int) comp.millisecond);
printf("Weekday is: %s\n", weekdays[comp.weekday]); /* 0=Sunday */
tags:
- time
- experimental
seealso:
- duk_components_to_time
introduced: 2.0.0