[英]What is the best way to have date and time input in html (from user) and receive in Javascript?
I want to get user input in form of date and time (html), turn them into proper Date objects (javascript) and store using Firebase backend. 我想以日期和时间(html)的形式获取用户输入,将它们转换为正确的Date对象(javascript)并使用Firebase后端进行存储。 This is to take user input for a future event and do something when that exact time comes.
这是为了接受用户对未来事件的输入,并在确切的时间到来时做一些事情。 But haven't found a convincing way to have a form or something in html.
但是还没有找到一种令人信服的方式来在html中使用表单或其他内容。
<input type="datetime-local" name="e">
In above, datetime-local is not only cumbersome but its AM/PM doesn't seem nice. 在上面,datetime-local不仅麻烦,而且其AM / PM看起来也不好。 Thanks.
谢谢。
Would flatpickr work for you? Flatpickr对您有用吗?
Demos at https://flatpickr.js.org/examples/ 演示在https://flatpickr.js.org/examples/
Your code might look like: 您的代码可能如下所示:
var options = { enableTime: true, dateFormat: "Ymd H:i", onChange: function(selectedDates, dateStr, instance) { alert("dates: " + selectedDates + " - dateStr: " + dateStr + " instance: " + instance); }, }; flatpickr(document.querySelector("#widget"), options);
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"> <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script> <div id="widget">Click this to edit time</div>
Read about more events at https://flatpickr.js.org/events/ 在https://flatpickr.js.org/events/了解更多事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.