dougekui1518 2017-06-22 05:32
浏览 79
已采纳

如何区分日期格式为dd / mm / yy或dd / mm / yyyy?

I'm trying to access the format of a given date value. I need to check whether the format is in dd/mm/yy or dd/mm/yyyy. I have used the following patterns with preg_match(), but they do not work.

'^\d{1,2}\/\d{1,2}\/\d{4}^'  //  dd/mm/yyyy

'^\d{1,2}\/\d{1,2}\/\d{2}^'  //  dd/mm/yy

Can someone help me to find the correct pattern?

  • 写回答

2条回答 默认 最新

  • doupai8533 2017-06-22 05:37
    关注

    Problems:

    1. This $ should be in end instead of ^. $ is for end of string.

    2. Don't forget delimiters /.

    Regular expression:

    /^\d{1,2}\/\d{1,2}\/\d{4}$/ for strings like 10/10/1111

    /^\d{1,2}\/\d{1,2}\/\d{2}$/ for strings like 10/10/11

    Try this code snippet here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况