kondakindi
IS-IT--Management
Hi,
I haev to get a specific date from the date the user enters and then 10 consective dates which are +14 each.Which means from the date i get i need everyday alternate sunday date coming up for then times.I have used the (GregorianCalender.DAy_OF_YEAR+date+14)but this doeesn't add properily some times it adds 13 or sometimes 12...
is it possible to get the alternate sunday from the date specified
The follwoing is my code:
The error is in the for loop then 10 dates are not i order:
import java.util.*;
import java.text.SimpleDateFormat;
import java.io.*;
import java.lang.*;
public class a {
private static String syear="2005";
private static String smonth="9";
private static String sday="5";
private static int sd=Integer.parseInt(sday);
private static final int payrollYear=2005;
private static final int payrollDay=3;
private static final int payrollMonth=7;
private static final int DayofWeek=1;
private static final GregorianCalendar payrollDate=
new GregorianCalendar(payrollYear, payrollMonth-1,payrollDay); //month starts from 0 in Gregorian Calendar.
private static final GregorianCalendar startDate=new GregorianCalendar(Integer.parseInt(syear),Integer.parseInt(smonth)-1,Integer.parseInt(sday));
public static void main(String arg[]) {
System.out.println(sday);
System.out.println(sd);
a a1=new a();
System.out.println(a1.getPayrollDate(startDate));
}
private String getPayrollDate(GregorianCalendar myDate){
int myYear = myDate.get(GregorianCalendar.YEAR);
int myDayofYear=myDate.get(GregorianCalendar.DAY_OF_YEAR);
int payrollYear=payrollDate.get(GregorianCalendar.YEAR);
int payrollDayofYear=payrollDate.get(GregorianCalendar.DAY_OF_YEAR);
System.out.println("myDayofYear = "+myDayofYear+"; payrollDayofYear = "+payrollDayofYear);
int yearday=0;
for(int i=payrollYear;i<myYear;i++){
if(new GregorianCalendar().isLeapYear(i))
yearday=yearday+366;
else
yearday=yearday+365;
}
int diffday=yearday+(myDayofYear-payrollDayofYear);
System.out.println("The diffday is "+diffday+" !");
int bal=14-(diffday%14);
int newbal = 0;
System.out.println(diffday%14);
System.out.println(bal+"dfgg");
if( (bal%14) >=5)
{
newbal = bal;
System.out.println(newbal+"nnnnn");
for(int y=1;y<10;y++)
{
System.out.println;
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
System.out.println("The new **** date is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
newbal=bal+1;
}
}
else
{
newbal =bal+14;
for(int y=1;y<10;y++)
{
System.out.println;
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
System.out.println("The new **** date by next is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
newbal=bal+14;
}
System.out.println("less time"+newbal);
}
//myDate.add(GregorianCalendar.DAY_OF_YEAR,bal); // Old code -- Vishu's comment
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
//System.out.println("The new **** date is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
return Integer.toString((myDate.get(GregorianCalendar.MONTH)+1))+"-"+Integer.toString(myDate.get(GregorianCalendar.DAY_OF_MONTH))+"-"+Integer.toString(myDate.get(GregorianCalendar.YEAR));
}
}
Thanks
I haev to get a specific date from the date the user enters and then 10 consective dates which are +14 each.Which means from the date i get i need everyday alternate sunday date coming up for then times.I have used the (GregorianCalender.DAy_OF_YEAR+date+14)but this doeesn't add properily some times it adds 13 or sometimes 12...
is it possible to get the alternate sunday from the date specified
The follwoing is my code:
The error is in the for loop then 10 dates are not i order:
import java.util.*;
import java.text.SimpleDateFormat;
import java.io.*;
import java.lang.*;
public class a {
private static String syear="2005";
private static String smonth="9";
private static String sday="5";
private static int sd=Integer.parseInt(sday);
private static final int payrollYear=2005;
private static final int payrollDay=3;
private static final int payrollMonth=7;
private static final int DayofWeek=1;
private static final GregorianCalendar payrollDate=
new GregorianCalendar(payrollYear, payrollMonth-1,payrollDay); //month starts from 0 in Gregorian Calendar.
private static final GregorianCalendar startDate=new GregorianCalendar(Integer.parseInt(syear),Integer.parseInt(smonth)-1,Integer.parseInt(sday));
public static void main(String arg[]) {
System.out.println(sday);
System.out.println(sd);
a a1=new a();
System.out.println(a1.getPayrollDate(startDate));
}
private String getPayrollDate(GregorianCalendar myDate){
int myYear = myDate.get(GregorianCalendar.YEAR);
int myDayofYear=myDate.get(GregorianCalendar.DAY_OF_YEAR);
int payrollYear=payrollDate.get(GregorianCalendar.YEAR);
int payrollDayofYear=payrollDate.get(GregorianCalendar.DAY_OF_YEAR);
System.out.println("myDayofYear = "+myDayofYear+"; payrollDayofYear = "+payrollDayofYear);
int yearday=0;
for(int i=payrollYear;i<myYear;i++){
if(new GregorianCalendar().isLeapYear(i))
yearday=yearday+366;
else
yearday=yearday+365;
}
int diffday=yearday+(myDayofYear-payrollDayofYear);
System.out.println("The diffday is "+diffday+" !");
int bal=14-(diffday%14);
int newbal = 0;
System.out.println(diffday%14);
System.out.println(bal+"dfgg");
if( (bal%14) >=5)
{
newbal = bal;
System.out.println(newbal+"nnnnn");
for(int y=1;y<10;y++)
{
System.out.println;
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
System.out.println("The new **** date is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
newbal=bal+1;
}
}
else
{
newbal =bal+14;
for(int y=1;y<10;y++)
{
System.out.println;
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
System.out.println("The new **** date by next is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
newbal=bal+14;
}
System.out.println("less time"+newbal);
}
//myDate.add(GregorianCalendar.DAY_OF_YEAR,bal); // Old code -- Vishu's comment
myDate.add(GregorianCalendar.DAY_OF_YEAR,newbal); // New code -- Vishu's comment
//System.out.println("The new **** date is " + myDate.get(GregorianCalendar.YEAR)+"/"+(myDate.get(GregorianCalendar.MONTH)+1)+"/"+myDate.get(GregorianCalendar.DAY_OF_MONTH));
return Integer.toString((myDate.get(GregorianCalendar.MONTH)+1))+"-"+Integer.toString(myDate.get(GregorianCalendar.DAY_OF_MONTH))+"-"+Integer.toString(myDate.get(GregorianCalendar.YEAR));
}
}
Thanks