7 Replies Latest reply: Dec 18, 2012 11:53 AM by DrClap RSS

    SimpleDateFormat for 24:00:00

    alekoc
      SimpleDateFormat frm1 = new SimpleDateFormat("ddMMyy-HHmm");
      long time0000 = 0;
      long time2400 = 0;
      try { 
          time0000 = frm1.parse("010113-0000").getTime();   // 1356991200000
          time2400 = frm1.parse("311212-2400").getTime();   // 1356991200000
      } catch (Exception ex) {
      }
      String time00 = frm1.format(time0000);    // 010113-0000 
      String time24 = frm1.format(time2400);    // 010113-0000 but I want 311212-2400
      SimpleDateFormat frm2 = new SimpleDateFormat("ddMMyy-kkmm");
      String time24k = frm2.format(time2400);   // 010113-2400 wrong
      What SimpleDateFormat should I use, if I want to get value “311212-2400” for time2400 variable?
        • 1. Re: SimpleDateFormat for 24:00:00
          918733
          The date formatter you are using is correct, but no date formatter will output hh:mm as 24:00. Does any clock read 24:00, once its midnight, in skips to the next day and in your case, next year.
          • 2. Re: SimpleDateFormat for 24:00:00
            alekoc
            It means I should calculate it by myself. I have requirement to use 24:00 instead of 00:00. What is the best way to make it?
            • 3. Re: SimpleDateFormat for 24:00:00
              EJP
              I suggest your requirement is wrong and should be reviewed. The fact that the JDK doesn't support it is pretty strong evidence in itself.
              • 4. Re: SimpleDateFormat for 24:00:00
                alekoc
                I don’t think so and IATA too. See IATA requirements from Standard Schedules Information Manual (SSIM) for example:
                SCHEDULED TIME OF AIRCRAFT ARRIVAL (STA): STA shall always be expressed by four digits indicating the 24 hours clock 
                timing and be in the range of 0001 through 2400. Arrivals at midnight (i.e. the end of the day) are always stated as 2400
                As you can see 00:00 time is prohibited for STA and I need to convert 00:00 into 24:00
                • 5. Re: SimpleDateFormat for 24:00:00
                  Kayaman
                  alekoc wrote:
                  As you can see 00:00 time is prohibited for STA and I need to convert 00:00 into 24:00
                  Then you can't rely on SimpleDateFormat.
                  • 6. Re: SimpleDateFormat for 24:00:00
                    alekoc
                    I found a decision how to format midnight time to 24:00:00. Subtract one millisecond to get previous date and use “kk” format for 24 hours in result. If I am wrong, let me know, please.
                    SimpleDateFormat frm1 = new SimpleDateFormat("ddMMyy-HHmmss");
                    long midnight = 0;
                    try {
                        midnight = frm1.parse("010113-000000").getTime();   // 1356991200000
                    } catch (Exception ex) {
                    }
                    SimpleDateFormat dateFrm = new SimpleDateFormat("ddMMyy-");
                    SimpleDateFormat time00 = new SimpleDateFormat("HHmmss");
                    SimpleDateFormat time24 = new SimpleDateFormat("kkmmss");
                    String t0000 = dateFrm.format(midnight) + time00.format(midnight);      // 010113-000000
                    String t2400 = dateFrm.format(midnight - 1) + time24.format(midnight);  // 311212-240000 
                    • 7. Re: SimpleDateFormat for 24:00:00
                      DrClap
                      I have seen flights with scheduled arrival and departure times of 23:59, but I don't recall ever seeing either 00:00 or 24:00 as an arrival or departure time. My guess: those airlines don't want to confuse their customers. Whether you call it 00:00 or 24:00, in either case it's going to lead to confusion.