Javascript 如何将日期格式从2019年12月12日转换为2019年12月12日

Javascript 如何将日期格式从2019年12月12日转换为2019年12月12日,javascript,Javascript,我将此blow代码用于我想要日期格式的laravel,从2019年12月12日到2019年12月12日 代码 <script> function DDMMYYYY(value, event) { let newValue = value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1'); const dayOrMonth = (index) => index % 2 === 1 && index <

我将此blow代码用于我想要日期格式的laravel,从2019年12月12日到2019年12月12日

代码

<script>
function DDMMYYYY(value, event) {
  let newValue = value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');

  const dayOrMonth = (index) => index % 2 === 1 && index < 4;

  // on delete key.  
  if (!event.data) {
    return value;
  }

  return newValue.split('').map((v, i) => dayOrMonth(i) ? v + '/' : v).join('');;
}
</script>

函数DDMMYYYY(值、事件){
让newValue=value.replace(/[^0-9]/g',).replace(/(\..*)\./g,$1');
常量dayOrMonth=(索引)=>index%2==1&&index<4;
//按delete键。
如果(!event.data){
返回值;
}
返回newValue.split(“”).map((v,i)=>dayOrMonth(i)?v+'/':v).join(“”);;
}
输入

       <div class="col-md-4">
                                                   <input  type="tel" maxlength="10" placeholder="DD/MM/YYYY"
oninput="this.value = DDMMYYYY(this.value, event)" required class="form-control  " name="certificate_issue_date" id="certificate_issue_date">
                                    </div>

为什么不在上一个
return
语句中将
/
替换为
-

函数DDMMYYYY(值、事件){
让newValue=value.replace(/[^0-9]/g',).replace(/(\..*)\./g,$1');
常量dayOrMonth=(索引)=>index%2==1&&index<4;
//按delete键。
如果(!event.data){
返回值;
}
返回newValue.split(“”).map((v,i)=>dayOrMonth(i)?v+'-':v).join(“”);;
}


我在这里没有看到任何php,只有javascript。@不管怎样,我只有这么多代码
用于电话号码,可能不允许
/
。您需要
。然后您应该适当地标记它。使用PHP标记而不是Javascript标记意味着您可能无法获得所需的帮助。