summaryrefslogtreecommitdiff
path: root/node_modules/node-addon-api/doc/date.md
blob: 959b4b9a6b452759bcde8f0647ce9d33bd94fd06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Date

`Napi::Date` class is a representation of the JavaScript `Date` object. The
`Napi::Date` class inherits its behavior from `Napi::Value` class
(for more info see [`Napi::Value`](value.md))

## Methods

### Constructor

Creates a new _empty_ instance of a `Napi::Date` object.

```cpp
Napi::Date::Date();
```

Creates a new _non-empty_ instance of a `Napi::Date` object.

```cpp
Napi::Date::Date(napi_env env, napi_value value);
```

 - `[in] env`: The environment in which to construct the `Napi::Date` object.
 - `[in] value`: The `napi_value` which is a handle for a JavaScript `Date`.

### New

Creates a new instance of a `Napi::Date` object.

```cpp
static Napi::Date Napi::Date::New(Napi::Env env, double value);
```

 - `[in] env`: The environment in which to construct the `Napi::Date` object.
 - `[in] value`: The time value the JavaScript `Date` will contain represented
  as the number of milliseconds since 1 January 1970 00:00:00 UTC.

Returns a new instance of `Napi::Date` object.

### ValueOf

```cpp
double Napi::Date::ValueOf() const;
```

Returns the time value as `double` primitive represented as the number of
 milliseconds since 1 January 1970 00:00:00 UTC.

## Operators

### operator double

Converts a `Napi::Date` value to a `double` primitive.

```cpp
Napi::Date::operator double() const;
```

### Example

The following shows an example of casting a `Napi::Date` value to a `double`
 primitive.

```cpp
double operatorVal = Napi::Date::New(Env(), 0); // Napi::Date to double
// or
auto instanceVal = info[0].As<Napi::Date>().ValueOf();
```