如何以特定日期格式(如“dd-MM-yyyy”)隐藏输入文本

问题描述 投票:0回答:1
javascript jquery
1个回答
0
投票

您可以使用正则表达式:

const regex = /(\d{2})\/(\d{2})\/(\d{4})/;
const value = '11/15/2017 12:00:00 AM'
const newValue = value.replace(regex, (_, month, day, year) => {
  return `${day}/${month}/${year}`
})
console.log(newValue) // 15/11/2017 12:00:00 AM

© www.soinside.com 2019 - 2024. All rights reserved.