list of all months between two dates in java

Ads
 

list of all months between two dates in java

Hi,

I want to get list of all months with year between two dates.

How to do this in Java?

Thanks

View Answers

May 16, 2018 at 6:44 AM

Hi,

This is the example code which can be used:

package test.app;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class YearMonthBetweenDates {
    public static void main(String[] args) {
        String date1 = "JAN-2017";
        String date2 = "APR-2019";

        DateFormat formater = new SimpleDateFormat("MMM-yyyy");

        Calendar beginCalendar = Calendar.getInstance();
        Calendar finishCalendar = Calendar.getInstance();

        try {
            beginCalendar.setTime(formater.parse(date1));
            finishCalendar.setTime(formater.parse(date2));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        DateFormat formaterYd = new SimpleDateFormat("yyyy-MM");

        while (beginCalendar.before(finishCalendar)) {

            String date =     formaterYd.format(beginCalendar.getTime()).toUpperCase();
            System.out.println(date);
            // Add One Month to get next Month
            beginCalendar.add(Calendar.MONTH, 1);
        }
    }
}

Thanks

Ads









Related Tutorials/Questions & Answers:
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
Advertisements
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two dates from the database table. I am using combo box to get the date. Problem
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example: <html> <head> <title>Number of days between two
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two
mysql between dates not between dates
mysql between dates not between dates  I am trying to list the data between dates and not between dates using join method ..but that not working for me
Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA... the difference between two dates. public class DateDiffDemo { public static...Difference in two dates  Hello there once again........ Dear Sir
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need... using Date.getTime() function. Once both Dates have been converted, subtracting
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers... all the even numbers between two numbers. For this first create a class named... all even numbers between 1 and this numbers.  Here is the code
Java get number of days between dates
Java get number of days between dates  ... the number of days between the two described dates. In order to get the number of days between two dates, the given example has set two dates by using
Comparing two dates in java
Comparing two dates in java In this example you will learn how to compare two dates in java.  java.util.Date provide a  method to compare two dates... date. The example below compares the two dates. import
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
java collision detection between two images
java collision detection between two images  java collision detection between two images
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing two dates. In  this example we are going to compare two date objects
Comparing two Dates in Java
Comparing two Dates in Java       In  this example we are going to compare two date objects using java.util.Date class. For comparing dates, we will be using compareTo
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
Comparing two Dates in Java with the use of after method
Comparing two Dates in Java with the use of after method... to compare two date objects in Java programming language. For comparing...() method to compare the dates. firstDate.after(secondDate); firstDate.after
Multiplication of two polynomials using linked list in java
Multiplication of two polynomials using linked list in java  I am doing a program "Multiplication of two polynomials using linked list in java... for polynomial linked list import java.util.Scanner; class Node { public int
PHP and MySQL BETWEEN dates with different years
PHP and MySQL BETWEEN dates with different years  I have a database... they should only show on the site when the date chosen falls between those dates. I thought it made sense to make use of the SQL BETWEEN statement, but it does
Java Swing Date Difference
Java Swing Date Difference In this tutorial, you will learn how to find the difference between two dates. Here is an example that accepts two dates from the user through swing components. The date entered by the user is then parsed
How to list even numbers between 1 and 100?
How to list even numbers between 1 and 100?  Hi, I Java to check if a number is even? How to list even numbers between 1 and 100? Thanks  ... ){ System.out.print(i+","); } Check complete example at Write a program to list all even
Version of com.cemerick>utc-dates dependency
List of Version of com.cemerick>utc-dates dependency
Comparing Dates in Java
Comparing Dates in Java       This example illustrates you how to compare two dates. Generally dates... two given dates. To compare dates the given program is helpful for application
how to get string between two characters
how to get string between two characters  hgow to get string from between two characters. ex:[email protected] from the above word i want a string between characters . and @ send the required method and give better example
How to manage cookie in between two JSP Pages
How to manage cookie in between two JSP Pages  How to manage cookie in between two JSP Pages   you can set cookies in response object e.g.response.addCookie(new Cookie("userName","Password")). Chandraprakash Sarathe

Ads