dongxin5054 2013-07-17 19:00
浏览 135

使用简单的用户输入格式转换自定义日期格式

I need to import text files from various sources that will contain dates in various formats. Given how many messed up pieces of data I have encountered in the test files I have gathered so far, I have decided to force the user to enter their date format before importing the file, e.g. MMDDYYYY or DD.MM.YYYY etc.

I can't expect these users to understand enough to enter Y-m-d or n/j/Y formats which would be easy enough to parse, and I can't rely on "standards" like "if a dash is used, then month comes before day", etc., so automatic parsing is very much out of the question.

The other issue with the usual PHP date formatting is that I can't predict if any date format will have single or double digits, and I don't know how createFromFormat would parse this if I give them a single digit when it expects a double digit...

So my first thought is to start by separating pure numeric dates from others and force the user to enter a full 8 digit date along with the format code - otherwise it becomes messy. But that's as far as I've gotten so far...

I thought about parsing date and format string side by side, but that again would cause issues with one-digit numbers if I'm not careful.

I haven't found anything that'll help in my case, but maybe I'm taking this from the wrong angle - maybe there's a Javascript or jQuery date format selection tool out there that's compatible with the PHP date formats...

Any suggestions on the best approach for this?

  • 写回答

3条回答 默认 最新

  • dongyun65343 2013-07-17 19:09
    关注

    jquery ui has a good datepicker, i have used it in several apps to ensure the format of dates is always the same

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c