Selected text date string - add to calendar option

Viewed 30

Bit of a wide question so feel free to ask for elaboration if needed but after some Googling I couldn't find an answer.

More curious than an actual need.

Is there a way of adding a tag, attribute (such as type=date) or JS (such as converting to a date object) to a text date string, like "Tuesday 3rd May, 2pm" that allows the user to select it and add it to their calendar?

Much like I can select an address text string and Google gives me the option to find that location on Google Maps.

Not looking for a concrete answer necessarily just some direction so I can have a play around.

1 Answers

You can play around with this:

<input type="date" />

<script>
    const input = document.querySelector('input');

    input.addEventListener('change', ({ target }) => {
        const date = new Date(target.value).toDateString();
        console.log(date);
    });
</script>

Related