正则表达式可以用于验证
  • 验证 email:

    const regMail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/

  • 验证时间格式:yyyy-mm-dd hh:mm:ss

    const regTime = /^(\d{4})(-)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/


获取当前时间:
function p(s) {
   
  return s < 10 ? '0' + s : s
}
function getTimeNow() {
   
  let timeNow
  var myDate = new Date()
  //获取当前年
  var year = myDate.getFullYear()
  //获取当前月
  var month = myDate.getMonth() + 1
  //获取当前日
  var date = myDate.getDate()
  var h = myDate.getHours() //获取当前小时数(0-23)
  var m = myDate.getMinutes() //获取当前分钟数(0-59)
  var s = myDate.getSeconds()
  timeNow =
    year + '-' + p(month) + '-' + p(date) + ' ' + p(h) + ':' + p(m) + ':' + p(s)
  return timeNow
}