title: Sort timestamps by date in Java
body: <p>I have class <code>Event</code> that has bunch of different variables like <strong>name</strong>, <strong>description</strong>, <strong>start time</strong> and <strong>end time</strong>, and then I have <code>Day</code> class that has variable date and <code>ArrayList</code> of these <code>Events</code>. Now I want to have ArrayList of <code>Days</code>, and every <code>Day</code> should contain <code>Events</code> that are on the same day. By default I get list of events and I need to create days based on this list. All times are in <strong>int</strong> <code>unix timestamp</code> format.</p>
  
  <p>Example to clarify what I am after for:</p>
  
  <pre><code>Day 25.11
  Event1
  Event2
  Event3
  
  Day 26.11
  Event1
  
  Day 27.11
  Event1
  Event2
  Event3
  Event4
  </code></pre>
  
  <p>there is the code I tried without working results:</p>
  
  <pre><code>private void getObjects(String url) throws JSONException, Exception {
      JSONObject jsonObject = new JSONObject(new NetTask().execute(url).get());
          JSONArray job1 = jsonObject.getJSONArray("events");
          ArrayList&lt;Event&gt; events = new ArrayList&lt;Event&gt;();
          Calendar calPrev = Calendar.getInstance();
          boolean first = true;
          for (int i = 0; i &lt; job1.length(); i++) {
              JSONObject myEventArray = job1.getJSONObject(i);
              int start = myEventArray.getInt("start");
              int end = myEventArray.getInt("end");
              String name = myEventArray.getString("name");
              String description = myEventArray.getString("description");
  
              if(first){
                  calPrev.setTimeInMillis(start*1000L);
                  events.add(new Event(start,end,name,description));
                  first = false;
              }else{
                  Calendar calCur = Calendar.getInstance();
                  calCur.setTimeInMillis(start*1000L);
  
                  if(calPrev.get(Calendar.YEAR) == calCur.get(Calendar.YEAR) &amp;&amp; calPrev.get(Calendar.DAY_OF_YEAR) == calCur.get(Calendar.DAY_OF_YEAR)){
                      events.add(new Event(start,end,name,description));
                  }else{
                      days.add(new Day(323,events)); // HERE I CREATE NEW DAY AND ADD IT TO ARRAY
                      events.clear();
                      events.add(new Event(start,end,name,description));
                  }
              }
          }
      }
  </code></pre>