Java - Create an array of times (15 minute) intervals between current time and a future set time












3














I'm trying to create an array of times from the current time to a set time, for example; the current time is 15:41, I would like that to be rounded up to the nearest quarter of an hour (15:45) and an array of 15 minute intervals to be created from 15:45 to a specified time lets say 23:30.



I've managed to create an array of times for a 24 hour period in 15 minute intervals and can't seem to get any further forward.



String quarterHours = {"00","15","30","45"};
String times = new String[24];

for(int i = 0; i < 24; i++) {
for(int j = 0; j < 4; j++) {
String time = i + ":" + quarterHours[j];
if(i < 10) {
time = "0" + time;
}
times[i] = "Today " + time;
}
}


The output from the above in a DialogList view within Android looks as follows:



enter image description here










share|improve this question






















  • You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
    – Federico klez Culloca
    Nov 12 at 15:48








  • 1




    Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
    – JamLis
    Nov 12 at 16:12
















3














I'm trying to create an array of times from the current time to a set time, for example; the current time is 15:41, I would like that to be rounded up to the nearest quarter of an hour (15:45) and an array of 15 minute intervals to be created from 15:45 to a specified time lets say 23:30.



I've managed to create an array of times for a 24 hour period in 15 minute intervals and can't seem to get any further forward.



String quarterHours = {"00","15","30","45"};
String times = new String[24];

for(int i = 0; i < 24; i++) {
for(int j = 0; j < 4; j++) {
String time = i + ":" + quarterHours[j];
if(i < 10) {
time = "0" + time;
}
times[i] = "Today " + time;
}
}


The output from the above in a DialogList view within Android looks as follows:



enter image description here










share|improve this question






















  • You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
    – Federico klez Culloca
    Nov 12 at 15:48








  • 1




    Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
    – JamLis
    Nov 12 at 16:12














3












3








3







I'm trying to create an array of times from the current time to a set time, for example; the current time is 15:41, I would like that to be rounded up to the nearest quarter of an hour (15:45) and an array of 15 minute intervals to be created from 15:45 to a specified time lets say 23:30.



I've managed to create an array of times for a 24 hour period in 15 minute intervals and can't seem to get any further forward.



String quarterHours = {"00","15","30","45"};
String times = new String[24];

for(int i = 0; i < 24; i++) {
for(int j = 0; j < 4; j++) {
String time = i + ":" + quarterHours[j];
if(i < 10) {
time = "0" + time;
}
times[i] = "Today " + time;
}
}


The output from the above in a DialogList view within Android looks as follows:



enter image description here










share|improve this question













I'm trying to create an array of times from the current time to a set time, for example; the current time is 15:41, I would like that to be rounded up to the nearest quarter of an hour (15:45) and an array of 15 minute intervals to be created from 15:45 to a specified time lets say 23:30.



I've managed to create an array of times for a 24 hour period in 15 minute intervals and can't seem to get any further forward.



String quarterHours = {"00","15","30","45"};
String times = new String[24];

for(int i = 0; i < 24; i++) {
for(int j = 0; j < 4; j++) {
String time = i + ":" + quarterHours[j];
if(i < 10) {
time = "0" + time;
}
times[i] = "Today " + time;
}
}


The output from the above in a DialogList view within Android looks as follows:



enter image description here







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 15:45









JamLis

187113




187113












  • You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
    – Federico klez Culloca
    Nov 12 at 15:48








  • 1




    Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
    – JamLis
    Nov 12 at 16:12


















  • You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
    – Federico klez Culloca
    Nov 12 at 15:48








  • 1




    Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
    – JamLis
    Nov 12 at 16:12
















You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
– Federico klez Culloca
Nov 12 at 15:48






You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes.
– Federico klez Culloca
Nov 12 at 15:48






1




1




Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
– JamLis
Nov 12 at 16:12




Thanks @K.Nicholas for the equation to round up to the nearest quarter hour. I will use this and combine with the marked answer to get my desired result. I didn't pay attention in maths class either, you're right.
– JamLis
Nov 12 at 16:12












4 Answers
4






active

oldest

votes


















3














You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes, like this:



String quarterHours = {"00","15","30","45"};
List<String> times = new ArrayList<String>; // <-- List instead of array

for(int i = 0; i < 24; i++) {
for(int j = 0; j < 4; j++) {
String time = i + ":" + quarterHours[j];
if(i < 10) {
time = "0" + time;
}
times.add("Today " + time); // <-- no need to care about indexes
}
}





share|improve this answer





















  • Thanks for this, much easier to change my starting time now without throwing array out of range errors.
    – JamLis
    Nov 12 at 16:11



















1














It would be much easier to work with the built-in Date/Time API, specifically LocalTime:



LocalTime time = LocalTime.now();

int minute = time.getMinute();

if (minute > 45) {
time = time.plusHours(1L).withMinute(0);
} else {
time = time.withMinute(minute < 30 ? minute < 15 ? 15 : 30: 45);
}

Stream.iterate(time.truncatedTo(ChronoUnit.MINUTES), t -> t.plusMinutes(15L))
.limit(5)
.forEach(System.out::println);


The above code outputs the following:



11:00
11:15
11:30
11:45
12:00


Your job will just be to figure out the math to limit the Stream size.






share|improve this answer





























    0














    Try this. Inserting items to array by times[i] is incorrect in this scenario. It will only count the first loop items



    public class Main
    {
    public static void main(String args)
    {
    String quarterHours = { "00", "15", "30", "45" };
    String times = new String[96];
    int count = 0;

    for (int i = 0; i < 24; i++)
    {
    for (int j = 0; j < 4; j++)
    {
    String time = i + ":" + quarterHours[j];
    if (i < 10)
    {
    time = "0" + time;
    }
    times[count] = "Today " + time;
    count++;
    }
    }

    for (int i = 0; i < times.length; i++)
    {
    System.out.println(times[i]);
    }
    }
    }





    share|improve this answer





























      0














      Problem in the previous approach was that the last minutes-turn wins and overwrites any previous result.



      I suggest using a List, it is much easier to handle. You don't need to take care for the size.



          String quarterHours = { "00", "15", "30", "45" };
      List<String> times = new ArrayList<>();

      for (int i = 0; i < 24; i++) {
      for (int j = 0; j < 4; j++) {
      String time = i + ":" + quarterHours[j];
      if (i < 10) {
      time = "0" + time;
      }
      times.add("Today " + time);
      }
      }
      System.out.println(times);


      Output:



      [Today 00:00, Today 00:15, Today 00:30, Today 00:45, Today 01:00, Today 01:15, Today 01:30, Today 01:45, Today 02:00, Today 02:15, Today 02:30, Today 02:45, Today 03:00, Today 03:15, Today 03:30, Today 03:45, Today 04:00, Today 04:15, Today 04:30, Today 04:45, Today 05:00, Today 05:15, Today 05:30, Today 05:45, Today 06:00, Today 06:15, Today 06:30, Today 06:45, Today 07:00, Today 07:15, Today 07:30, Today 07:45, Today 08:00, Today 08:15, Today 08:30, Today 08:45, Today 09:00, Today 09:15, Today 09:30, Today 09:45, Today 10:00, Today 10:15, Today 10:30, Today 10:45, Today 11:00, Today 11:15, Today 11:30, Today 11:45, Today 12:00, Today 12:15, Today 12:30, Today 12:45, Today 13:00, Today 13:15, Today 13:30, Today 13:45, Today 14:00, Today 14:15, Today 14:30, Today 14:45, Today 15:00, Today 15:15, Today 15:30, Today 15:45, Today 16:00, Today 16:15, Today 16:30, Today 16:45, Today 17:00, Today 17:15, Today 17:30, Today 17:45, Today 18:00, Today 18:15, Today 18:30, Today 18:45, Today 19:00, Today 19:15, Today 19:30, Today 19:45, Today 20:00, Today 20:15, Today 20:30, Today 20:45, Today 21:00, Today 21:15, Today 21:30, Today 21:45, Today 22:00, Today 22:15, Today 22:30, Today 22:45, Today 23:00, Today 23:15, Today 23:30, Today 23:45]






      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265558%2fjava-create-an-array-of-times-15-minute-intervals-between-current-time-and-a%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes, like this:



        String quarterHours = {"00","15","30","45"};
        List<String> times = new ArrayList<String>; // <-- List instead of array

        for(int i = 0; i < 24; i++) {
        for(int j = 0; j < 4; j++) {
        String time = i + ":" + quarterHours[j];
        if(i < 10) {
        time = "0" + time;
        }
        times.add("Today " + time); // <-- no need to care about indexes
        }
        }





        share|improve this answer





















        • Thanks for this, much easier to change my starting time now without throwing array out of range errors.
          – JamLis
          Nov 12 at 16:11
















        3














        You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes, like this:



        String quarterHours = {"00","15","30","45"};
        List<String> times = new ArrayList<String>; // <-- List instead of array

        for(int i = 0; i < 24; i++) {
        for(int j = 0; j < 4; j++) {
        String time = i + ":" + quarterHours[j];
        if(i < 10) {
        time = "0" + time;
        }
        times.add("Today " + time); // <-- no need to care about indexes
        }
        }





        share|improve this answer





















        • Thanks for this, much easier to change my starting time now without throwing array out of range errors.
          – JamLis
          Nov 12 at 16:11














        3












        3








        3






        You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes, like this:



        String quarterHours = {"00","15","30","45"};
        List<String> times = new ArrayList<String>; // <-- List instead of array

        for(int i = 0; i < 24; i++) {
        for(int j = 0; j < 4; j++) {
        String time = i + ":" + quarterHours[j];
        if(i < 10) {
        time = "0" + time;
        }
        times.add("Today " + time); // <-- no need to care about indexes
        }
        }





        share|improve this answer












        You're overwriting the time each cycle of the inner loop. You should use a List<String> instead and just append without worrying about indexes, like this:



        String quarterHours = {"00","15","30","45"};
        List<String> times = new ArrayList<String>; // <-- List instead of array

        for(int i = 0; i < 24; i++) {
        for(int j = 0; j < 4; j++) {
        String time = i + ":" + quarterHours[j];
        if(i < 10) {
        time = "0" + time;
        }
        times.add("Today " + time); // <-- no need to care about indexes
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 15:53









        Federico klez Culloca

        15.6k134275




        15.6k134275












        • Thanks for this, much easier to change my starting time now without throwing array out of range errors.
          – JamLis
          Nov 12 at 16:11


















        • Thanks for this, much easier to change my starting time now without throwing array out of range errors.
          – JamLis
          Nov 12 at 16:11
















        Thanks for this, much easier to change my starting time now without throwing array out of range errors.
        – JamLis
        Nov 12 at 16:11




        Thanks for this, much easier to change my starting time now without throwing array out of range errors.
        – JamLis
        Nov 12 at 16:11













        1














        It would be much easier to work with the built-in Date/Time API, specifically LocalTime:



        LocalTime time = LocalTime.now();

        int minute = time.getMinute();

        if (minute > 45) {
        time = time.plusHours(1L).withMinute(0);
        } else {
        time = time.withMinute(minute < 30 ? minute < 15 ? 15 : 30: 45);
        }

        Stream.iterate(time.truncatedTo(ChronoUnit.MINUTES), t -> t.plusMinutes(15L))
        .limit(5)
        .forEach(System.out::println);


        The above code outputs the following:



        11:00
        11:15
        11:30
        11:45
        12:00


        Your job will just be to figure out the math to limit the Stream size.






        share|improve this answer


























          1














          It would be much easier to work with the built-in Date/Time API, specifically LocalTime:



          LocalTime time = LocalTime.now();

          int minute = time.getMinute();

          if (minute > 45) {
          time = time.plusHours(1L).withMinute(0);
          } else {
          time = time.withMinute(minute < 30 ? minute < 15 ? 15 : 30: 45);
          }

          Stream.iterate(time.truncatedTo(ChronoUnit.MINUTES), t -> t.plusMinutes(15L))
          .limit(5)
          .forEach(System.out::println);


          The above code outputs the following:



          11:00
          11:15
          11:30
          11:45
          12:00


          Your job will just be to figure out the math to limit the Stream size.






          share|improve this answer
























            1












            1








            1






            It would be much easier to work with the built-in Date/Time API, specifically LocalTime:



            LocalTime time = LocalTime.now();

            int minute = time.getMinute();

            if (minute > 45) {
            time = time.plusHours(1L).withMinute(0);
            } else {
            time = time.withMinute(minute < 30 ? minute < 15 ? 15 : 30: 45);
            }

            Stream.iterate(time.truncatedTo(ChronoUnit.MINUTES), t -> t.plusMinutes(15L))
            .limit(5)
            .forEach(System.out::println);


            The above code outputs the following:



            11:00
            11:15
            11:30
            11:45
            12:00


            Your job will just be to figure out the math to limit the Stream size.






            share|improve this answer












            It would be much easier to work with the built-in Date/Time API, specifically LocalTime:



            LocalTime time = LocalTime.now();

            int minute = time.getMinute();

            if (minute > 45) {
            time = time.plusHours(1L).withMinute(0);
            } else {
            time = time.withMinute(minute < 30 ? minute < 15 ? 15 : 30: 45);
            }

            Stream.iterate(time.truncatedTo(ChronoUnit.MINUTES), t -> t.plusMinutes(15L))
            .limit(5)
            .forEach(System.out::println);


            The above code outputs the following:



            11:00
            11:15
            11:30
            11:45
            12:00


            Your job will just be to figure out the math to limit the Stream size.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 at 15:55









            Jacob G.

            15.2k52162




            15.2k52162























                0














                Try this. Inserting items to array by times[i] is incorrect in this scenario. It will only count the first loop items



                public class Main
                {
                public static void main(String args)
                {
                String quarterHours = { "00", "15", "30", "45" };
                String times = new String[96];
                int count = 0;

                for (int i = 0; i < 24; i++)
                {
                for (int j = 0; j < 4; j++)
                {
                String time = i + ":" + quarterHours[j];
                if (i < 10)
                {
                time = "0" + time;
                }
                times[count] = "Today " + time;
                count++;
                }
                }

                for (int i = 0; i < times.length; i++)
                {
                System.out.println(times[i]);
                }
                }
                }





                share|improve this answer


























                  0














                  Try this. Inserting items to array by times[i] is incorrect in this scenario. It will only count the first loop items



                  public class Main
                  {
                  public static void main(String args)
                  {
                  String quarterHours = { "00", "15", "30", "45" };
                  String times = new String[96];
                  int count = 0;

                  for (int i = 0; i < 24; i++)
                  {
                  for (int j = 0; j < 4; j++)
                  {
                  String time = i + ":" + quarterHours[j];
                  if (i < 10)
                  {
                  time = "0" + time;
                  }
                  times[count] = "Today " + time;
                  count++;
                  }
                  }

                  for (int i = 0; i < times.length; i++)
                  {
                  System.out.println(times[i]);
                  }
                  }
                  }





                  share|improve this answer
























                    0












                    0








                    0






                    Try this. Inserting items to array by times[i] is incorrect in this scenario. It will only count the first loop items



                    public class Main
                    {
                    public static void main(String args)
                    {
                    String quarterHours = { "00", "15", "30", "45" };
                    String times = new String[96];
                    int count = 0;

                    for (int i = 0; i < 24; i++)
                    {
                    for (int j = 0; j < 4; j++)
                    {
                    String time = i + ":" + quarterHours[j];
                    if (i < 10)
                    {
                    time = "0" + time;
                    }
                    times[count] = "Today " + time;
                    count++;
                    }
                    }

                    for (int i = 0; i < times.length; i++)
                    {
                    System.out.println(times[i]);
                    }
                    }
                    }





                    share|improve this answer












                    Try this. Inserting items to array by times[i] is incorrect in this scenario. It will only count the first loop items



                    public class Main
                    {
                    public static void main(String args)
                    {
                    String quarterHours = { "00", "15", "30", "45" };
                    String times = new String[96];
                    int count = 0;

                    for (int i = 0; i < 24; i++)
                    {
                    for (int j = 0; j < 4; j++)
                    {
                    String time = i + ":" + quarterHours[j];
                    if (i < 10)
                    {
                    time = "0" + time;
                    }
                    times[count] = "Today " + time;
                    count++;
                    }
                    }

                    for (int i = 0; i < times.length; i++)
                    {
                    System.out.println(times[i]);
                    }
                    }
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 at 15:53









                    Sand

                    1,020113




                    1,020113























                        0














                        Problem in the previous approach was that the last minutes-turn wins and overwrites any previous result.



                        I suggest using a List, it is much easier to handle. You don't need to take care for the size.



                            String quarterHours = { "00", "15", "30", "45" };
                        List<String> times = new ArrayList<>();

                        for (int i = 0; i < 24; i++) {
                        for (int j = 0; j < 4; j++) {
                        String time = i + ":" + quarterHours[j];
                        if (i < 10) {
                        time = "0" + time;
                        }
                        times.add("Today " + time);
                        }
                        }
                        System.out.println(times);


                        Output:



                        [Today 00:00, Today 00:15, Today 00:30, Today 00:45, Today 01:00, Today 01:15, Today 01:30, Today 01:45, Today 02:00, Today 02:15, Today 02:30, Today 02:45, Today 03:00, Today 03:15, Today 03:30, Today 03:45, Today 04:00, Today 04:15, Today 04:30, Today 04:45, Today 05:00, Today 05:15, Today 05:30, Today 05:45, Today 06:00, Today 06:15, Today 06:30, Today 06:45, Today 07:00, Today 07:15, Today 07:30, Today 07:45, Today 08:00, Today 08:15, Today 08:30, Today 08:45, Today 09:00, Today 09:15, Today 09:30, Today 09:45, Today 10:00, Today 10:15, Today 10:30, Today 10:45, Today 11:00, Today 11:15, Today 11:30, Today 11:45, Today 12:00, Today 12:15, Today 12:30, Today 12:45, Today 13:00, Today 13:15, Today 13:30, Today 13:45, Today 14:00, Today 14:15, Today 14:30, Today 14:45, Today 15:00, Today 15:15, Today 15:30, Today 15:45, Today 16:00, Today 16:15, Today 16:30, Today 16:45, Today 17:00, Today 17:15, Today 17:30, Today 17:45, Today 18:00, Today 18:15, Today 18:30, Today 18:45, Today 19:00, Today 19:15, Today 19:30, Today 19:45, Today 20:00, Today 20:15, Today 20:30, Today 20:45, Today 21:00, Today 21:15, Today 21:30, Today 21:45, Today 22:00, Today 22:15, Today 22:30, Today 22:45, Today 23:00, Today 23:15, Today 23:30, Today 23:45]






                        share|improve this answer


























                          0














                          Problem in the previous approach was that the last minutes-turn wins and overwrites any previous result.



                          I suggest using a List, it is much easier to handle. You don't need to take care for the size.



                              String quarterHours = { "00", "15", "30", "45" };
                          List<String> times = new ArrayList<>();

                          for (int i = 0; i < 24; i++) {
                          for (int j = 0; j < 4; j++) {
                          String time = i + ":" + quarterHours[j];
                          if (i < 10) {
                          time = "0" + time;
                          }
                          times.add("Today " + time);
                          }
                          }
                          System.out.println(times);


                          Output:



                          [Today 00:00, Today 00:15, Today 00:30, Today 00:45, Today 01:00, Today 01:15, Today 01:30, Today 01:45, Today 02:00, Today 02:15, Today 02:30, Today 02:45, Today 03:00, Today 03:15, Today 03:30, Today 03:45, Today 04:00, Today 04:15, Today 04:30, Today 04:45, Today 05:00, Today 05:15, Today 05:30, Today 05:45, Today 06:00, Today 06:15, Today 06:30, Today 06:45, Today 07:00, Today 07:15, Today 07:30, Today 07:45, Today 08:00, Today 08:15, Today 08:30, Today 08:45, Today 09:00, Today 09:15, Today 09:30, Today 09:45, Today 10:00, Today 10:15, Today 10:30, Today 10:45, Today 11:00, Today 11:15, Today 11:30, Today 11:45, Today 12:00, Today 12:15, Today 12:30, Today 12:45, Today 13:00, Today 13:15, Today 13:30, Today 13:45, Today 14:00, Today 14:15, Today 14:30, Today 14:45, Today 15:00, Today 15:15, Today 15:30, Today 15:45, Today 16:00, Today 16:15, Today 16:30, Today 16:45, Today 17:00, Today 17:15, Today 17:30, Today 17:45, Today 18:00, Today 18:15, Today 18:30, Today 18:45, Today 19:00, Today 19:15, Today 19:30, Today 19:45, Today 20:00, Today 20:15, Today 20:30, Today 20:45, Today 21:00, Today 21:15, Today 21:30, Today 21:45, Today 22:00, Today 22:15, Today 22:30, Today 22:45, Today 23:00, Today 23:15, Today 23:30, Today 23:45]






                          share|improve this answer
























                            0












                            0








                            0






                            Problem in the previous approach was that the last minutes-turn wins and overwrites any previous result.



                            I suggest using a List, it is much easier to handle. You don't need to take care for the size.



                                String quarterHours = { "00", "15", "30", "45" };
                            List<String> times = new ArrayList<>();

                            for (int i = 0; i < 24; i++) {
                            for (int j = 0; j < 4; j++) {
                            String time = i + ":" + quarterHours[j];
                            if (i < 10) {
                            time = "0" + time;
                            }
                            times.add("Today " + time);
                            }
                            }
                            System.out.println(times);


                            Output:



                            [Today 00:00, Today 00:15, Today 00:30, Today 00:45, Today 01:00, Today 01:15, Today 01:30, Today 01:45, Today 02:00, Today 02:15, Today 02:30, Today 02:45, Today 03:00, Today 03:15, Today 03:30, Today 03:45, Today 04:00, Today 04:15, Today 04:30, Today 04:45, Today 05:00, Today 05:15, Today 05:30, Today 05:45, Today 06:00, Today 06:15, Today 06:30, Today 06:45, Today 07:00, Today 07:15, Today 07:30, Today 07:45, Today 08:00, Today 08:15, Today 08:30, Today 08:45, Today 09:00, Today 09:15, Today 09:30, Today 09:45, Today 10:00, Today 10:15, Today 10:30, Today 10:45, Today 11:00, Today 11:15, Today 11:30, Today 11:45, Today 12:00, Today 12:15, Today 12:30, Today 12:45, Today 13:00, Today 13:15, Today 13:30, Today 13:45, Today 14:00, Today 14:15, Today 14:30, Today 14:45, Today 15:00, Today 15:15, Today 15:30, Today 15:45, Today 16:00, Today 16:15, Today 16:30, Today 16:45, Today 17:00, Today 17:15, Today 17:30, Today 17:45, Today 18:00, Today 18:15, Today 18:30, Today 18:45, Today 19:00, Today 19:15, Today 19:30, Today 19:45, Today 20:00, Today 20:15, Today 20:30, Today 20:45, Today 21:00, Today 21:15, Today 21:30, Today 21:45, Today 22:00, Today 22:15, Today 22:30, Today 22:45, Today 23:00, Today 23:15, Today 23:30, Today 23:45]






                            share|improve this answer












                            Problem in the previous approach was that the last minutes-turn wins and overwrites any previous result.



                            I suggest using a List, it is much easier to handle. You don't need to take care for the size.



                                String quarterHours = { "00", "15", "30", "45" };
                            List<String> times = new ArrayList<>();

                            for (int i = 0; i < 24; i++) {
                            for (int j = 0; j < 4; j++) {
                            String time = i + ":" + quarterHours[j];
                            if (i < 10) {
                            time = "0" + time;
                            }
                            times.add("Today " + time);
                            }
                            }
                            System.out.println(times);


                            Output:



                            [Today 00:00, Today 00:15, Today 00:30, Today 00:45, Today 01:00, Today 01:15, Today 01:30, Today 01:45, Today 02:00, Today 02:15, Today 02:30, Today 02:45, Today 03:00, Today 03:15, Today 03:30, Today 03:45, Today 04:00, Today 04:15, Today 04:30, Today 04:45, Today 05:00, Today 05:15, Today 05:30, Today 05:45, Today 06:00, Today 06:15, Today 06:30, Today 06:45, Today 07:00, Today 07:15, Today 07:30, Today 07:45, Today 08:00, Today 08:15, Today 08:30, Today 08:45, Today 09:00, Today 09:15, Today 09:30, Today 09:45, Today 10:00, Today 10:15, Today 10:30, Today 10:45, Today 11:00, Today 11:15, Today 11:30, Today 11:45, Today 12:00, Today 12:15, Today 12:30, Today 12:45, Today 13:00, Today 13:15, Today 13:30, Today 13:45, Today 14:00, Today 14:15, Today 14:30, Today 14:45, Today 15:00, Today 15:15, Today 15:30, Today 15:45, Today 16:00, Today 16:15, Today 16:30, Today 16:45, Today 17:00, Today 17:15, Today 17:30, Today 17:45, Today 18:00, Today 18:15, Today 18:30, Today 18:45, Today 19:00, Today 19:15, Today 19:30, Today 19:45, Today 20:00, Today 20:15, Today 20:30, Today 20:45, Today 21:00, Today 21:15, Today 21:30, Today 21:45, Today 22:00, Today 22:15, Today 22:30, Today 22:45, Today 23:00, Today 23:15, Today 23:30, Today 23:45]







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 12 at 15:55









                            michaeak

                            749315




                            749315






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265558%2fjava-create-an-array-of-times-15-minute-intervals-between-current-time-and-a%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Xamarin.iOS Cant Deploy on Iphone

                                Glorious Revolution

                                Dulmage-Mendelsohn matrix decomposition in Python