1# Date
2
3`Napi::Date` class is a representation of the JavaScript `Date` object. The
4`Napi::Date` class inherits its behavior from the `Napi::Value` class
5(for more info see [`Napi::Value`](value.md)).
6
7## Methods
8
9### Constructor
10
11Creates a new _empty_ instance of a `Napi::Date` object.
12
13```cpp
14Napi::Date::Date();
15```
16
17Creates a new _non-empty_ instance of a `Napi::Date` object.
18
19```cpp
20Napi::Date::Date(napi_env env, napi_value value);
21```
22
23 - `[in] env`: The environment in which to construct the `Napi::Date` object.
24 - `[in] value`: The `napi_value` which is a handle for a JavaScript `Date`.
25
26### New
27
28Creates a new instance of a `Napi::Date` object.
29
30```cpp
31static Napi::Date Napi::Date::New(Napi::Env env, double value);
32```
33
34 - `[in] env`: The environment in which to construct the `Napi::Date` object.
35 - `[in] value`: The time value the JavaScript `Date` will contain represented
36  as the number of milliseconds since 1 January 1970 00:00:00 UTC.
37
38Returns a new instance of `Napi::Date` object.
39
40### ValueOf
41
42```cpp
43double Napi::Date::ValueOf() const;
44```
45
46Returns the time value as `double` primitive represented as the number of
47 milliseconds since 1 January 1970 00:00:00 UTC.
48
49## Operators
50
51### operator double
52
53Converts a `Napi::Date` value to a `double` primitive.
54
55```cpp
56Napi::Date::operator double() const;
57```
58
59### Example
60
61The following shows an example of casting a `Napi::Date` value to a `double`
62 primitive.
63
64```cpp
65double operatorVal = Napi::Date::New(Env(), 0); // Napi::Date to double
66// or
67auto instanceVal = info[0].As<Napi::Date>().ValueOf();
68```
69