I would like to compare a date to the current date. could you please tell me how to do that in java.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Get the dates (however you get them, in the code below it is new Date()) and then use the getTime() to get the Unix time (offset from January 1, 1970, 00:00:00 GMT) to do the comparison
You can also use the compareTo method, or as is pointed out in another answer the before and after methods.
EDIT based on comment below:
To parse a date from a String you can use the SimpleDateFormat class (there are other ways too).
For example here is some code I am using for that: