mirror of https://github.com/svaarala/duktape.git
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.
46 lines
1.5 KiB
46 lines
1.5 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 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"
|
|
};
|
|
|
|
/* 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
|
|
- experimental
|
|
|
|
seealso:
|
|
- duk_components_to_time
|
|
|
|
introduced: 2.0.0
|
|
|