Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get a timestamp in ClojureScript?

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

like image 240
yazz.com Avatar asked Jan 02 '15 10:01

yazz.com


2 Answers

You can use

(.getTime (js/Date.))

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

like image 102
Symfrog Avatar answered Nov 25 '22 14:11

Symfrog


The most efficient way is this

(.now js/Date)

Other answers needlessly create a Date object.

like image 42
mikeyreilly Avatar answered Nov 25 '22 13:11

mikeyreilly