1

I want to show date and time in Clojurescript, but anything I tried did not work. Can anyone help with an example? I tried to use JavaScript datatime in different syntax ways, but none of them worked. Thank you.

Update

I tired these but they did not work:

(. (js/Date))
(js/Date.)
(now (js/Date))
(js/Date.new)
(js/Date.new.)
(.new (js/Date)

I just wont to show the current date and time on the screen. Inside a [:h3] tag in the .cljs file.

7
  • 1
    It's very unclear what you actually want. You write that you tried some things - can you post them? What exactly do you mean by "show date"? If you mean just creating a date as in new Date() in JS, it's (js/Date.) in CLJS. Commented Nov 22, 2022 at 5:23
  • Please add the code you have tried and how it failed (e.g. errors, stacktraces, logs, ...) so we can improve on it. Commented Nov 22, 2022 at 7:44
  • @EugenePakhomov that did not work for me, the page goes blank when I use that. Commented Nov 22, 2022 at 12:22
  • @cfrick I added the things I tried. The problem is I don't know how to use java introp and did not fond anything helpful by searching. Commented Nov 22, 2022 at 12:23
  • @EugenePakhomov should [:h3 (js/Date.)] show the date? Or am I doing that wrongly? Commented Nov 22, 2022 at 12:25

1 Answer 1

2
(.toLocaleString (js/Date.))
;; => "22/11/2022, 17:17:22"

and in [:h3]:

[:h3 (.toLocaleString (js/Date.))]

If you want other formatting you can mix and match the available methods on a Date instance using interop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.