Hello there!
Is there any way to verify the format of date and time on a web page? (Not the current date and time)
For example, I have a date and time 13.05.2022 17h07. I want to verify if it is following the right format dd.MM.YYYY HHhMM.
Thank you in advance!
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import com.kms.katalon.core.util.KeywordUtil
String data0 = "13.05.2022 17h02"
assert validateDateTime(data0)
String data1 = "13.05.2022 17h99"
assert validateDateTime(data1)
boolean validateDateTime(String str) {
DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern("dd.MM.uuuu HH'h'mm")
try {
LocalDateTime ldt = LocalDateTime.parse(str, dtFormatter)
return true
} catch (Exception e) {
KeywordUtil.markWarning(e.getMessage())
return false
}
}
Hello @edpangilinan0814 ,
Try this one.
String DateInput=“13.05.2022 17h07”
SimpleDateFormat sdf =new SimpleDateFormat(“dd.MM.yyyy HH’h’mm”,Locale.ENGLISH)
Date DateFormatCheck = sdf.parse(DateInput);
if (sdf.format(DateFormatCheck).equals(DateInput)){
println(“Match”)
}else{
println(“not Match”)
}