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

后端 未结 12 1359
感情败类
感情败类 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条回答
  •  独厮守ぢ
    2021-02-02 16:35

    You need to check your UI requirements. If you want script-enabled support only, they you can go with any of your panopoly of scripts and run with whatever date/time format they provide into a hidden field.

    However, if you need the user entry in a textbox, then you're faced with some decisions:

    • Is the date/time format rigid? e.g. mm/dd/yyy hh:mm:ss format only?
    • Or loosely defined, to allow for the "today", "tomorrow", "23 Jan" style entries?
    • Will the formats be locale-specific? e.g. mm/dd/yyyy vs. dd/mm/yyyy

    Validation methods depend on your decisions on requirements.

    I like the jQuery date-picker plugin. It'll allow output in specific formats.

提交回复
热议问题