see date in java
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date date = new Date(System.currentTimeMillis());
System.out.println(date);
}
}
see date in java
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date date = new Date(System.currentTimeMillis());
System.out.println(date);
}
}
validate date java
The current way is to use the calendar class. It has the setLenient method that will validate the date and throw and exception if it is out of range as in your example.
Forgot to add: If you get a calendar instance and set the time using your date, this is how you get the validation.
Calendar cal = Calendar.getInstance();
cal.setLenient(false);
cal.setTime(yourDate);
try {
cal.getTime();
}
catch (Exception e) {
System.out.println("Invalid date");
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us