New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moment.js should support HTML5 inputs like datetime-local #3928

tkrotoff opened this Issue Apr 26, 2017 · 6 comments


None yet
5 participants

tkrotoff commented Apr 26, 2017

Moment.js should support out of the box HTML5 inputs datetime-local, date, time, week, month.
Instead of writing:

<input type="datetime-local" value={start.format('YYYY-MM-DDTHH:mm')} />
<input type="date" value={start.format('YYYY-MM-DD')} />
<input type="time" value={start.format('HH:mm:ss')} />

something like:

<input type="datetime-local" value={start.toHtmlInput_datetime_local()} />
<input type="date" value={start.toHtmlInput_date()} />
<input type="time" value={start.toHtmlInput_time()} />
<input type="week" value={start.toHtmlInput_week()} />
<input type="month" value={start.toHtmlInput_month()} />

=> more explicit, less error-prone (ss vs SS, local vs UTC, yyyy vs YYYY...)

datetime-local expects "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS" format
date expects "yyyy-MM-dd"
time expects "HH:mm", "HH:mm:ss" or "HH:mm:ss.SSS"
week expects "yyyy-Www"
month expects "yyyy-MM"
(taken from error messages given by Chrome 57. Yes Chrome speaks yyyy and dd instead of YYYY and DD, see #1603)


This comment has been minimized.


icambron commented May 2, 2017

I think the way we've been thinking about these is to create constants of the form moment.DATETIME_LOCAL = "YYYY-MM-DD" and letting you just moment().format(moment.DATETIME_LOCAL). That seems like a good way to help with this without adding a whole bunch of new functions.

@icambron icambron added the New Feature label May 2, 2017


This comment has been minimized.


maggiepint commented May 13, 2017

I think we can up-for-grabs this one. Those kinds of constants are simple enough.


This comment has been minimized.

tkrotoff commented May 13, 2017

I like the constants approach better than my original proposition.
Would love to see these constants added to Moment.


This comment has been minimized.

nitte93 commented May 16, 2017

Hi, I want to contribute in fixing this issue. This is going to be my first PR. I have forked and setup the project locally. Gone through It would be helpful if you guys provide some specific pointers for me to get started.


This comment has been minimized.

cmdrwebdev commented Aug 10, 2017

Is this still open?


This comment has been minimized.


icambron commented Aug 16, 2017

@cmdrwebdev yup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment