Generating Dates Between Start and End in Java

Posted on August 11, 2012 at 13:14 Java No Comments

Yesterday I had to generate a list of dates given two inputs. Having no Internet connection yet, I eagerly searched for help through my Android phone. Stack Overflow would’ve instantly helped me if I didn’t leave immediately after reading “Joda Time”. The thought of not needing some library for such an ideally simple task was simply there. Then there was this, which compiled but never ran. :faint:

In my case, the checking that the end date should be greater than the start date was already handled somewhere else so I already skipped it. Also, instead of actual Dates, I only needed Strings (but I do intend to convert this into a generic utility class). So, yeah, here you go:

final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();

try {
   startDate.setTime(DATE_FORMAT.parse("2012/08/01"));
   endDate.setTime(DATE_FORMAT.parse("2012/08/10"));

   ArrayList<String> includedDates = new ArrayList<String>();

   while(!startDate.equals(endDate)) {
      String date = DATE_FORMAT.format(startDate.getTime());
      includedDates.add(date);
      startDate.add(Calendar.DATE, 1);
   } includedDates.add(DATE_FORMAT.format(endDate.getTime()));

   for(String date : includedDates) {
      System.out.println(date);
   }
} catch(Exception e) {}

Today I checked back on the supposedly second working solution I cited above, copy-pasted the code, and successfully ran it. :wtf:

Some Weekend Playlist

Posted on July 7, 2012 at 14:37 Entehtainment 3 Comments

I have always been a music person. (Wait, does the term even make sense? You should get the point, I just know.) It was four years ago when I decided to organize my files by year. That suggests that for this year I have a 2012 subfolder in my Music folder. But it’s never been the case that all songs in one are released on that year too. If now I hear and happen to like a song which was released in 1988, that would still go to 2012.

Calvin Harris - Let's Go (Ft. Ne-Yo) Carly Rae Jepsen - Call Me Maybe fun. - Some Nights Gym Class Heroes - The Fighter (Ft. Ryan Tedder)
Karmin - Brokenhearted Katy Perry - Wide Awake Natasha Bedingfield - Neon Lights Nicki Minaj - Fly (Ft. Rihanna)
Nicki Minaj - Marilyn Monroe Simple Plan - Summer Paradise (Ft. Sean Paul) Wiz Khalifa - Young, Wild & Free (Ft. Snoop Dogg) Joshua Radin - Streetlight

Moving forward as of May, as picky as I am, I have decided to further categorize the songs by month for multiple reasons you wouldn’t be quite interested in hearing. I do it by simply appending a [<month>] before the filename. Alright, this post is becoming more random by the minute. Just check out my June playlist above which I have been listening to the weekend after the great Guimaras escape. Right now it’s again in an infinite loop (repeat, side by side shuffle, in layman’s term). Will your taste buds match mine? :tongue: