Skip to content

Instantly share code, notes, and snippets.

@sidward35
Created January 3, 2018 08:33
Show Gist options
  • Save sidward35/e105d473ba07b3e1d3d59d0be6e4eac3 to your computer and use it in GitHub Desktop.
Save sidward35/e105d473ba07b3e1d3d59d0be6e4eac3 to your computer and use it in GitHub Desktop.
Print all the dates of 2018 in yyyy-mm-dd format
//Super inefficient, quick-hacks hardcoded method!!
for(int x=1; x<=12; x++){
if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
for(int y=1; y<=31; y++){
if(x<10 && y<10) System.out.printf("2018-0%1d-0%1d\n", x, y);
else if (x<10 && y>9) System.out.printf("2018-0%1d-%2d\n", x, y);
else if (x>9 && y<10) System.out.printf("2018-%2d-0%1d\n", x, y);
else if (x>9 && y>9) System.out.printf("2018-%2d-%2d\n", x, y);
}
}else if(x==2){
for(int y=1; y<=28; y++){
if(x<10 && y<10) System.out.printf("2018-0%1d-0%1d\n", x, y);
else if (x<10 && y>9) System.out.printf("2018-0%1d-%2d\n", x, y);
else if (x>9 && y<10) System.out.printf("2018-%2d-0%1d\n", x, y);
else if (x>9 && y>9) System.out.printf("2018-%2d-%2d\n", x, y);
}
}else{
for(int y=1; y<=30; y++){
if(x<10 && y<10) System.out.printf("2018-0%1d-0%1d\n", x, y);
else if (x<10 && y>9) System.out.printf("2018-0%1d-%2d\n", x, y);
else if (x>9 && y<10) System.out.printf("2018-%2d-0%1d\n", x, y);
else if (x>9 && y>9) System.out.printf("2018-%2d-%2d\n", x, y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment