Regarding Date Display
hi,
i'm writing code to display dates between fromdate and todate
for example 06-13-07 to 07-13-07(MM/DD/yy format)
i need to display dates between these dates
like
06-14-07
06-15-07
06-16-07
.
.so on upto
.
07-13-07
i'm fail to do this
i'm getting but it is not accurate
plz help me regarding this
thank you
one and all
[426 byte] By [
reetua] at [2007-11-27 7:30:23]

> Use an instance of Calendar, initialize it to the
> start date and for each single new date call
> add(Calendar.DATE, 1) on this instance until the end
> is reached. What does your code look like so far?
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.io.*;
class DisplayDate
{
public static void main( String[] args )
{
String todate="7/13/2007";
String[] monthNames = {"january","february","march","april","may","june",
"july","august","september","october","november","december"};
// String jun=monthNames[5];
// String july=monthNames[6];
//String[] dayNames = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15",};
TimeZone local = TimeZone.getDefault();
//SimpleDateFormat sdf=new SimpleDateFormat();
Calendar c=new GregorianCalendar();
//sdf.setTimeZone( local );
// String fromdate = sdf.format( new Date() );
// System.out.println(fromdate );
int month=c.get(Calendar.MONTH)+1;
int date=c.get(Calendar.DATE);
int year=c.get(Calendar.YEAR);
String fromdate=month+"/"+date+"/"+year;
System.out.println(month+"/"+date+"/ "+year);
System.out.println( todate);
int len =todate.length();
int len1=fromdate.length();
System.out.println(len+" "+len1);
for(int i=1;i<31;i++)
{
System.out.println(monthNames[5]+"-"+i+"-"+"2007");
}
for(int i=1;i<=31;i++)
{
System.out.println(monthNames[6]+"-"+i+"-"+"2007");
}
}
}
by executing above code i'm getting output,here i'm displaying without using fromdate, todate
but i need to display by using fromdate ,todate
plz help me regarding this
reetua at 2007-7-12 19:10:35 >

Like this?
Date from = /*...*/;
Date until = /*...*/;
Calendar cal = Calendar.getInstance();
Calendar ref = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy");
cal.setTime(from.getTime());
ref.setTime(until.getTime());
System.out.println(format.format(from));
while ((cal.get(Calendar.YEAR) < ref.get(Calendar.YEAR)) ||
(cal.get(Calendar.MONTH) < ref.get(Calendar.MONTH)) ||
(cal.get(Calendar.DATE) < ref.get(Calendar.DATE)))
{
cal.add(Calendar.DATE, 1);
System.out.println(format.format(cal.getTime()));
}
thank you very much for your reply
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.io.*;
import java.text.SimpleDateFormat;
class DisplayDate1
{
public static void main( String[] args )
{
Date from =new Date(06/13/07);
Date until =new Date(07/13/07);
//System.out.print(from);
//System.out.print(until);
Calendar cal = Calendar.getInstance();
Calendar ref = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy");
cal.setTime(from);
ref.setTime(until);
//System.out.println(format.format(from));
while ((cal.get(Calendar.YEAR) < ref.get(Calendar.YEAR)) ||
(cal.get(Calendar.MONTH) < ref.get(Calendar.MONTH)) ||
(cal.get(Calendar.DATE) < ref.get(Calendar.DATE)))
{
cal.add(Calendar.DATE, 1);
System.out.println(format.format(cal.getTime()));
}
}
}
i need to display dates from 06/13/07 to 07/13/07(ie. current date to todate)
reetua at 2007-7-12 19:10:35 >
