Last active
April 14, 2017 15:06
-
-
Save BurakAkyildiz/984b0e312a4b7785a99e00ce010ad756 to your computer and use it in GitHub Desktop.
2 tarih arasında ayın belirli gününün seçilen güne denk gelen ayları yazan algoritma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author b.akyildiz | |
*/ | |
public class GetDayCount { | |
static int[] mountDays = new int[]{31,28,31,30,31,30,31,31,30,31,30,31}; | |
public static void main(String[] args) { | |
GetDayCount.getMonthDayCount(0, 0, 0, 1900, 1, 2000); | |
} | |
/* | |
startDay = 0; // 0 = pazartesi, ... ,6 = pazar aramanın başladığı gün | |
startYear = aramanın başlama yılı | |
endYear = aramanın bitiş yılı | |
endMonth = son arama yapılan ay | |
dayIndexToSearch = 0; // Ayın kaçıncı günü denetlenecek ? | |
dayToSearch = 0; // 0 = pazartesi, ... ,6 = pazar hangi gün denetlenecek | |
*/ | |
public static int getMonthDayCount(int dayToSearch,int dayIndexToSearch,int startDay,int startYear,int endMonth,int endYear) | |
{ | |
long startMilis = System.currentTimeMillis(); | |
int totalDays = 0; | |
int foundDays = 0; | |
for (int i = startYear; i <= endYear; i++) { | |
int currentEndMonth = 12; | |
if( i == endYear ) | |
currentEndMonth = endMonth; | |
for (int j = 0; j < currentEndMonth; j++) { | |
if( (startDay + totalDays + dayIndexToSearch) % 7 == dayToSearch) | |
{ | |
System.out.println(dayToSearch+1+"/"+(j+1)+"/"+i); | |
foundDays++; | |
} | |
totalDays += mountDays[j]; | |
if( i % 4 == 0 && j == 1) // Artık gün | |
{ | |
if( i % 100 == 0 ) | |
{ | |
if( i % 400 == 0 && i % 4000 != 0) | |
totalDays++; | |
} | |
else | |
{ | |
totalDays++; | |
} | |
} | |
} | |
} | |
System.out.println("Geçen Milisaniye : "+(System.currentTimeMillis()-startMilis)); | |
System.out.println("Bulunan Gün : "+foundDays); | |
System.out.println("Toplam Gün : "+totalDays); | |
return foundDays; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment