How to extract date from string using javascript

后端 未结 5 1619
轮回少年
轮回少年 2021-01-21 11:35

How does one extract a date from a string using javascript? It can be in the following formats:

31.07.2014

07.31.2014

2014.07.31 the same format but divi

5条回答
  •  我在风中等你
    2021-01-21 12:14

    RegEX will help you to extract date with Different Type of format and It returns as Array,

    let str="dd/mm/yyyy06/06/2018 yyyy/mm/dd 2018/02/12 d/m/yy 1/1/18 dd/mm/yy 18/12/12 mm/d/yyyy 12/2/2018 m/dd/yyyy 1/12/2018 yy/m/d 18/1/1 yy/mm/d 18/12/1 yyyy/2018/1/1";
    str.match(/(\d{1,4}([.\-/])\d{1,2}([.\-/])\d{1,4})/g);
    

    Reference Link From regextester

提交回复
热议问题