Scala/Lift check if date is correctly formatted

前端 未结 5 1242
半阙折子戏
半阙折子戏 2020-12-31 17:20

I have a date input box in my lift application, and I want to check that a user-entered date is in correct format: dd/mm/yyyy.

How can I write a reg

5条回答
  •  我在风中等你
    2020-12-31 17:56

    from this we can validate date in string as well as we get the expected date response by parsing in the format like "dd/MM/yyyy".

      try {  val format = DateTimeFormat.forPattern("dd/MM/yyyy")
      format.parseMillis(dateInString)
      val df = new SimpleDateFormat("dd/MM/yyyy")
      val newDate = df.parse(dateInString)
      true
        } catch {
          case e: ParseException => false
    
          case e: IllegalArgumentException => false
        }
    

提交回复
热议问题