How do you get a timestamp in ClojureScript?
Asked Answered
R

2

17

How can I get a timestamp in ClojureScript, similar to Unix's timestamp, a single number that represents the current time and date, as a number. I know that:

if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}

can be used in Javascript but I want to know if there is a ClojureScript equivalant

Rillings answered 2/1, 2015 at 10:28 Comment(0)
P
28

You can use

(.getTime (js/Date.))

or you could also use now or epoch from cljs-time.

Pavia answered 2/1, 2015 at 21:27 Comment(0)
A
10

The most efficient way is this

(.now js/Date)

Other answers needlessly create a Date object.

Art answered 23/4, 2020 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.