WASM js-sys date and formatting help

Hi all,

I am new to Rust and couldn't figure this one out, probably it is something simple for others with more experience. Hopefully it will also help other new users as well.

I want to get today's date in WASM in en-US date format. I am able to achieve it with chorono but wanted to try the same with js-sys since it uses browser JS libraries.

What I did so far:
I used js-sys "new_0" to get current date and then used "to_utc_string" method:

I tried to use js-sys "Intl::DateTimeFormat" struct and "format" method, which supposed to convert "js-sys date" to given locale specific format but I couldn't make it work:

As per the MDN documentation link of "format" method of "DateTimeFormat", it should take date as parameter but in Rust implementation it doesn't take any parameter so I am not sure how to pass that value.

"format" method returns "Function" struct so probably something need to be done with it but I have no clue and no example is provided.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.