What's the best approach to get Date/Time input from the user?

后端 未结 12 1360
感情败类
感情败类 2021-02-02 15:34

This is a wheel that\'s been re-invented again and again over the years.

The Problem: The user needs to input a Date/Time

Basic considerations

12条回答
  •  -上瘾入骨i
    2021-02-02 16:15

    My preference is for a text input with an elipsis button next to it:

    Enter a date [        ] [...]
    

    The elipsis would pop up a calendar to populate the text input, but the user can type in a date if they want. Validation should be done when the "OK" button for the form is pressed - trying to do date validation on a character by character basis is doomed, in my experience.

    The validation should be sophisticated and allow expressions like

    "today"
    "Tomorrow"
    "23 Jan"
    

    etc.

    Edit: In reply to some comments, one could do validation when the text edit loses focus (though I hate that kind of thing) in which case the edit content could change from "23 Jan" to "23-01-2009" to indicate that the exprssion was understood.

提交回复
热议问题