How to new Date()?


#1

Hi,

How do I do the equivalent of new Date()?
I’ve tried let now = new Js.Date();, but I get this error:

>>>> Start compiling
[1/2] Building src/Component1.mlast
File "/home/kabo/Documents/lmt/src/Component1.re", line 15, characters 22-23:
Error: 73: <syntax error>
File "/home/kabo/Documents/lmt/src/Component1.re", line 1, characters 0-0:
Error: Error while running external preprocessor
Command line: /home/kabo/Documents/lmt/node_modules/bs-platform/lib/refmt.exe --print binary '/home/kabo/Documents/lmt/src/Component1.re' > /tmp/ocamlppd16d79

ninja: error: rebuilding 'build.ninja': subcommand failed
>>>> Finish compiling(exit: 1)

There doesn’t seem to be much info on new or Date in the docs…


#2

You don’t need the new keyword here.

let now  = Js.Date.make();

Example:

The api of Js.Date can be found here:
https://bucklescript.github.io/bucklescript/api/Js.Date.html


#3

That’s exactly what I was looking for, thanks.

Another gotcha for the next guy reading this:
This doesn’t work:

let now = Js.Date.make();
Js.log(now.toISOString());

Here’s how to do it:

let now = Js.Date.make();
Js.log(Js.Date.toISOString(now));