Skip to content
Advertisement

Tag: calendar

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

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:

How to get the weekday of a Date?

I want to get the day of week from the Java Date object when I have an array of Date in String with me. Does anyone know the answer to this? Answer You can get the day-integer like that: If you need the output to be “Tue” rather than 3, instead of going through a calendar, just reformat the string:

Java: Get week number from any date?

I have a small program that displays the current week from todays date, like this: And then a JLabel that displays the week number: So right now I’d like to have a JTextField where you can enter a date and the JLabel will update with the week number of that date. I’m really not sure how to do this as

Android Format date with time zone

I need to format the date into a specific string. I used SimpleDateFormat class to format the date using the pattern “yyyy-MM-dd’T’HH:mm:ssZ” it returns current date as “2013-01-04T15:51:45+0530” but I need as “2013-01-04T15:51:45+05:30”. Below is the coding used, Output: formatted string: 2013-01-04T15:51:45+0530 I need the format as 2013-01-04T15:51:45+05:30 just adding the colon in between gmt time. Because I’m working on

How to get last month/year in java?

How do I find out the last month and its year in Java? e.g. If today is Oct. 10 2012, the result should be Month = 9 and Year = 2012. If today is Jan. 10 2013, the result should be Month = 12 and Year = 2012. Answer Your solution is here but instead of addition you need to

java get week of year for given a date

how can I get a week of the year given a date? I tried the following code: and i obtain: sDateCalendar lun apr 23 11:58:39 CEST 2012 iStartWeek 2012 3 while the correct week of year is 17. Can someone help me ? Answer You are using sDateCalendar.WEEK_OF_YEAR, which is the static integer WEEK_OF_YEAR, see the source of the java.util.Calendar

Advertisement