U
U
userib2021-10-02 19:00:14
JavaScript
userib, 2021-10-02 19:00:14

The data type of the value is datetime-local. How to convert datetime-local value to seconds?

My html page has a date and time input field

<input type="datetime-local" id="beginlocaldate" name="begindate" step=1></input>


I extract the value of the datetime-local field in js

let periodbegin=document.querySelector('input[type="datetime-local"][id="beginlocaldate"]');
console.log(periodbegin.value);


1. What type will periodbegin.value be? (On https://developer.mozilla.org/en/docs/Web/HTML/Ele... , https://developer.mozilla.org/en/docs/Web/API/DOMString it is indicated that the datetime value is local is of type DOMString

2. If the field value type is DOMString, how to convert it to seconds, and how to convert datetime-local value to seconds in general,

3. How to convert datetime-local value to UNIX epoch seconds?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergski, 2021-10-02
@sergski

Everything is as usual - use new Date() and getTime()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question