|
| 1 | +--- |
| 2 | +layout: api-docs |
| 3 | +category: api-docs |
| 4 | +subCategory: doc |
| 5 | +menu: Haxe |
| 6 | +title: Date |
| 7 | +target: Clay (Native) |
| 8 | +permalink: api-docs/clay-native/Date/ |
| 9 | +--- |
| 10 | + |
| 11 | +# Date |
| 12 | + |
| 13 | +<div class="type-hierarchy"><strong>Date</strong> (Class)</div> |
| 14 | + |
| 15 | +The Date class provides a basic structure for date and time related |
| 16 | +information. Date instances can be created by |
| 17 | + |
| 18 | +- `new Date()` for a specific date, |
| 19 | +- `Date.now()` to obtain information about the current time, |
| 20 | +- `Date.fromTime()` with a given timestamp or |
| 21 | +- `Date.fromString()` by parsing from a String. |
| 22 | + |
| 23 | +There are some extra functions available in the `DateTools` class. |
| 24 | + |
| 25 | +In the context of Haxe dates, a timestamp is defined as the number of |
| 26 | +milliseconds elapsed since 1st January 1970 UTC. |
| 27 | + |
| 28 | +## Supported range |
| 29 | + |
| 30 | +Due to platform limitations, only dates in the range 1970 through 2038 are |
| 31 | +supported consistently. Some targets may support dates outside this range, |
| 32 | +depending on the OS at runtime. The `Date.fromTime` method will not work with |
| 33 | +timestamps outside the range on any target. |
| 34 | + |
| 35 | +## Static Members |
| 36 | + |
| 37 | +<div class="signature field-method has-description" id="now"><code><span class="field-name">now</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="operator">:</span> <a href="#" class="type-link">Date</a></code><a class="header-anchor" href="#now"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 38 | + |
| 39 | +Returns a Date representing the current local time. |
| 40 | +| Returns | |
| 41 | +|---------| |
| 42 | +| [Date](/api-docs/clay-native/Date/) | |
| 43 | + |
| 44 | +<hr class="field-separator" /> |
| 45 | + |
| 46 | +<div class="signature field-method has-description" id="fromTime"><code><span class="field-name">fromTime</span><span class="parenthesis">(</span><span class="arg-name">t</span><span class="operator">:</span> <a href="/api-docs/clay-native/Float/" class="type-link">Float</a><span class="parenthesis">)</span><span class="operator">:</span> <a href="#" class="type-link">Date</a></code><a class="header-anchor" href="#fromTime"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 47 | + |
| 48 | +Creates a Date from the timestamp (in milliseconds) `t`. |
| 49 | + |
| 50 | +| Name | Type | |
| 51 | +|------|------| |
| 52 | +| `t` | [Float](/api-docs/clay-native/Float/) | |
| 53 | + |
| 54 | +| Returns | |
| 55 | +|---------| |
| 56 | +| [Date](/api-docs/clay-native/Date/) | |
| 57 | + |
| 58 | +<hr class="field-separator" /> |
| 59 | + |
| 60 | +<div class="signature field-method has-description" id="fromString"><code><span class="field-name">fromString</span><span class="parenthesis">(</span><span class="arg-name">s</span><span class="operator">:</span> <a href="/api-docs/clay-native/String/" class="type-link">String</a><span class="parenthesis">)</span><span class="operator">:</span> <a href="#" class="type-link">Date</a></code><a class="header-anchor" href="#fromString"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 61 | + |
| 62 | +Creates a Date from the formatted string `s`. The following formats are |
| 63 | +accepted by the function: |
| 64 | + |
| 65 | +- `"YYYY-MM-DD hh:mm:ss"` |
| 66 | +- `"YYYY-MM-DD"` |
| 67 | +- `"hh:mm:ss"` |
| 68 | + |
| 69 | +The first two formats expressed a date in local time. The third is a time |
| 70 | +relative to the UTC epoch. |
| 71 | + |
| 72 | +| Name | Type | |
| 73 | +|------|------| |
| 74 | +| `s` | [String](/api-docs/clay-native/String/) | |
| 75 | + |
| 76 | +| Returns | |
| 77 | +|---------| |
| 78 | +| [Date](/api-docs/clay-native/Date/) | |
| 79 | + |
| 80 | +## Instance Members |
| 81 | + |
| 82 | +<div class="signature field-method has-description" id="getTime"><code><span class="field-name">getTime</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="operator">:</span> <a href="/api-docs/clay-native/Float/" class="type-link">Float</a></code><a class="header-anchor" href="#getTime"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 83 | + |
| 84 | +Returns the timestamp (in milliseconds) of `this` date. |
| 85 | +On cpp and neko, this function only has a second resolution, so the |
| 86 | +result will always be a multiple of `1000.0`, e.g. `1454698271000.0`. |
| 87 | +To obtain the current timestamp with better precision on cpp and neko, |
| 88 | +see the `Sys.time` API. |
| 89 | + |
| 90 | +For measuring time differences with millisecond accuracy on |
| 91 | +all platforms, see `haxe.Timer.stamp`. |
| 92 | +| Returns | |
| 93 | +|---------| |
| 94 | +| [Float](/api-docs/clay-native/Float/) | |
| 95 | + |
| 96 | +<hr class="field-separator" /> |
| 97 | + |
| 98 | +<div class="signature field-method has-description" id="toString"><code><span class="field-name">toString</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="operator">:</span> <a href="/api-docs/clay-native/String/" class="type-link">String</a></code><a class="header-anchor" href="#toString"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 99 | + |
| 100 | +Returns a string representation of `this` Date in the local timezone |
| 101 | +using the standard format `YYYY-MM-DD HH:MM:SS`. See `DateTools.format` for |
| 102 | +other formatting rules. |
| 103 | +| Returns | |
| 104 | +|---------| |
| 105 | +| [String](/api-docs/clay-native/String/) | |
| 106 | + |
| 107 | +<hr class="field-separator" /> |
| 108 | + |
| 109 | +<div class="signature field-method has-description" id="new"><code><span class="field-name">new</span><span class="parenthesis">(</span><span class="arg-name">year</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="operator">,</span> <span class="arg-name">month</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="operator">,</span> <span class="arg-name">day</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="operator">,</span> <span class="arg-name">hour</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="operator">,</span> <span class="arg-name">min</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="operator">,</span> <span class="arg-name">sec</span><span class="operator">:</span> <a href="/api-docs/clay-native/Int/" class="type-link">Int</a><span class="parenthesis">)</span><span class="operator">:</span> <a href="/api-docs/clay-native/Void/" class="type-link">Void</a></code><a class="header-anchor" href="#new"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 110 | + |
| 111 | +Creates a new date object from the given arguments. |
| 112 | + |
| 113 | +The behaviour of a Date instance is only consistent across platforms if |
| 114 | +the the arguments describe a valid date. |
| 115 | + |
| 116 | +- month: 0 to 11 (note that this is zero-based) |
| 117 | +- day: 1 to 31 |
| 118 | +- hour: 0 to 23 |
| 119 | +- min: 0 to 59 |
| 120 | +- sec: 0 to 59 |
| 121 | + |
| 122 | +| Name | Type | |
| 123 | +|------|------| |
| 124 | +| `year` | [Int](/api-docs/clay-native/Int/) | |
| 125 | +| `month` | [Int](/api-docs/clay-native/Int/) | |
| 126 | +| `day` | [Int](/api-docs/clay-native/Int/) | |
| 127 | +| `hour` | [Int](/api-docs/clay-native/Int/) | |
| 128 | +| `min` | [Int](/api-docs/clay-native/Int/) | |
| 129 | +| `sec` | [Int](/api-docs/clay-native/Int/) | |
| 130 | + |
| 131 | +## Private Members |
| 132 | + |
| 133 | +<div class="signature field-var no-description" id="mSeconds"><code><span class="field-name">mSeconds</span><span class="operator">:</span> <a href="/api-docs/clay-native/Float/" class="type-link">Float</a></code><a class="header-anchor" href="#mSeconds"><span aria-hidden="true" class="header-anchor__symbol">#</span></a></div> |
| 134 | + |
0 commit comments