最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable previous today's previous time in html input datetime-local picker - Stack Overflow

programmeradmin4浏览0评论

I am trying to figure out solution to fix the issue of not allowing user to select previous time. I mean for eg

Today's date: 17-02-2019
Current Time: 02:30 PM

So when user selects today's date and selects the time 02:30 AM instead of PM. Here the time is past so user shouldn’t be allowed to select the AM time because the current time is 02:30 PM

As per MDN docs the below code should work but it’s not working.

   <input type="datetime-local" min="2019-02-17T14:30" />

As per below docs it shouldn’t allow me to select time like eg 9:00 AM, 10:00 AM even 02:29 PM but I am allowed to select. I even tried their fiddle example but their examples do allow me to select past time

I am trying to figure out solution to fix the issue of not allowing user to select previous time. I mean for eg

Today's date: 17-02-2019
Current Time: 02:30 PM

So when user selects today's date and selects the time 02:30 AM instead of PM. Here the time is past so user shouldn’t be allowed to select the AM time because the current time is 02:30 PM

As per MDN docs the below code should work but it’s not working.

   <input type="datetime-local" min="2019-02-17T14:30" />

As per below docs it shouldn’t allow me to select time like eg 9:00 AM, 10:00 AM even 02:29 PM but I am allowed to select. I even tried their fiddle example but their examples do allow me to select past time

https://developer.mozilla/en-US/docs/Web/HTML/Element/input/datetime-local

Share Improve this question edited Feb 22, 2019 at 13:24 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Feb 17, 2019 at 10:30 Hemadri DasariHemadri Dasari 34k40 gold badges124 silver badges166 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

This may be because of the format , you may need to strip off the seconds. In console.log you can see the seconds but when setting the min value the seconds and microseconds need to strip off

var today = new Date().toISOString();
console.log(today)
document.getElementById("daTi").min = '2019-02-17T10:38';
<input type="datetime-local" id='daTi' />

发布评论

评论列表(0)

  1. 暂无评论