Show seconds on input type=date-local in Chrome

2020-06-01 02:46发布

In google chrome if I set the value of an input of type datetime-local to a time containing seconds where the seconds value is 0 Chrome decides not to show the seconds value on the input, meaning the user can't set the seconds at all.

E.g. If I set the value to 2013-10-24T20:36:01 then Chrome will show an input and the user can change the day, month, year, hours, minutes and seconds to whatever they want (including 0). If I set the value to 2013-10-24T20:36:00 then the seconds part disappears. I can understand it not being shown if no value for seconds was passed in but I am explicitly setting them to 0 so I would have assumed it would show them.

The reason why this is a problem is because I am reading the times from a database and if any of them have been set to 0 seconds the user can't change the time without hacking it with developer tools!

Am I missing something?

Thanks!

1条回答
狗以群分
2楼-- · 2020-06-01 03:06

Adding step attribute will resolve your issue.

<input type=datetime-local value="2013-10-24T20:36:00" step="1">

The default value of step attribute is 60 (one minute).

查看更多
登录 后发表回答