Skip to content
Advertisement

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 throw a ParseException, so you should

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 uses the user’s local to parse the string. Keep

Unparsable Date with colon-separated timezone

I’m trying to parse this String 2014-04-04T14:28:38+02:00 It should be ISO 8601 format. But i can’t parse it to a correct Date. I’ve tried the following: But I get always the message “unparseable Date” I can not change the example because it’s a value from a webservice. Could it be there is a probleme with “+02:00” instead of “+0200” ?

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 constructor:

Advertisement