简体   繁体   English

用html(来自用户)输入日期和时间并用Javascript接收日期和时间的最佳方法是什么?

[英]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.

相关问题 从用户接收数字输入的正确方法 - Javascript - Proper Way to receive number Input From User - Javascript 允许用户在html / javascript中指定日期/时间戳范围的最干净方法是什么? - What's the cleanest way to allow a user to specify a range of date / time stamps in html / javascript? 在javascript中比较日期对象的时间组件的最佳方法是什么 - What is the best way of comparing the time component of a date object in javascript 通过javascript合并和评估用户输入的最佳方法是什么? - What is the best way to combine and evaluate user input through javascript? 处理 JavaScript 以允许用户访问 html 页面的最佳方法是什么? - What is the best way to handle a JavaScript to allow a user to access an html page? 基于Java用户输入,设置Date()对象的正确方法是什么 - what is the correct way to set a Date() object based on user input in Javascript 如何检测用户在 html 和 javascript 的输入框中键入的内容 - how to detect what the user have typed in input box in html & javascript 用html表单中的输入值进行计算的最佳方法是什么? - What is best way to make a calculation with input values from a html form? 将日期从客户端(Javascript)发送到WebApi的最佳方法是什么 - What is the best way to send Date from client(Javascript) to WebApi 用Javascript从html表中删除行的最佳方法是什么? - What's the best way in Javascript to delete row from html table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM