简体   繁体   中英

JavaScript for entering date based on value in an HTML text box

Is there a library for entering text values in an HTML text box which are then converted into a date? For example, typing "Next Monday" puts next Monday's date in, "Next month" puts today's date + 1 month, "+4" puts today's date + 4 days, etc.

You might want to consider moment.js , which solves this sort of problem.

For natural language date-parsing, check out chrono.js .

chrono.parseDate(document.getElementById("my-input").value)

For an input value of "next week" , this will return today's date plus seven days, in a Date type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM