Skip to content

Tag: date

How to compare two string dates in Java?

I have two dates in String format like below – I want to make sure startDate should be less than endDate. startDate should not be greater than endDate. How can I compare these two dates and return boolean accordingly? Answer Convert them to an actual Date object, then call before. Recall that parse will…

Finding date of birth from age in java

Hello all I am creating a program for finding the date of birth when the exact age is given. For example if age of a man is 21 years 10 months and 22 days(up to current date) how can i find the exact date of birth. I will be thankful if anyone help me with isuue. What i tried is

Get month number from month name

I have this. How to get month number which contain in monthName variable? Thanks! Answer Use Java’s Calendar class. It can parse any given string into a valid calendar instance. Here is an example (assuming that the month is in english). You can specify the language in SimpleDateFormat: By default, Java…

SimpleDateFormat parse returns bad date

I am using SimpleDateFormat in order to parse a String. Here is an example: When I check dirDate in debug mode, or print it, the date I get is Mon Apr 07 14:35:42 FET 2014. Why do I get such an offset? It cannot be counted as a timezone offset(although it seems already wrong to apply an offset). How can

Comparing dates with JUnit testing

Hello I’m new to the site and have a issue with my application using JUnit testing. My issue is when I try to compare the Date method with itself it always fails. I printed the Date object in the test to see the problem and always end up with the package name and random letters. Here is the Date constru…