简体   繁体   English

如何让我的用户以特定格式插入日期?

[英]How do I let my users insert a date in a specific format?

In an internal CMS/Order System we have a 'deadline' input field. 在内部CMS /订单系统中,我们有一个“截止日期”输入字段。 Currently this is just a plain text and stored as such in the database (varchar). 目前,这只是一个纯文本,并存储在数据库(varchar)中。 I want to change this since I can't work with this data in any way. 我想改变这一点,因为我不能与此数据以任何方式工作 The input should be that of a date (day-month-year). 输入应该是日期(日 - 月 - 年)的输入。

What is the best way to do this? 做这个的最好方式是什么? The solutions I came up with: 我提出的解决方案:

  1. Use HTML5's <input type="date" /> . 使用HTML5的<input type="date" /> This could work since we only use modern browsers internally. 这可能有效,因为我们只在内部使用现代浏览器。
  2. jQuery datepicker. jQuery datepicker。 I havent really worked with jQuery before but I think this is a solid soluton. 我之前没有真正使用过jQuery,但我认为这是一个可靠的解决方案。
  3. Let users do whatever they want and use strtotime() ? 让用户做他们想做的事情并使用strtotime()

Any thoughts on how to handle this? 有关如何处理这个问题的任何想法?

My simple suggestion is, 我的简单建议是,

You can give a label text like Note: Date format should be "dd-mm-yyyy" below the text box. 您可以给出标签文本,如注意:日期格式应在文本框下方为“dd-mm-yyyy”

Then you can validate the input format in Javascript & PHP. 然后,您可以在Javascript和PHP中验证输入格式。 There are so many validation scripts available. 有很多验证脚本可用。

(or) (要么)

Use Datepicker for user friendly. 使用Datepicker用户友好。

I think you can use jquery date picker because its more userfriendly and keeping the datepicker readonly there is no need of further validation for date.Also you can change the desired format of date. 我认为你可以使用jquery日期选择器,因为它更友好,并且只保留日期选择器,不需要进一步验证date.Also你可以改变所需的日期格式。

For reference check these links 供参考检查这些链接

http://jqueryui.com/datepicker/ http://jqueryui.com/datepicker/

http://keith-wood.name/datepick.html http://keith-wood.name/datepick.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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