'Selected text date string - add to calendar option

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.



Solution 1:[1]

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mstephen19