Hey guys
I have a method that is calculating a time based two JComboBox selections.
I am returning the time as a Date object but it prints the date and time, when I say
'cal.getTime()'. The date is always the same, the format is Thu Jan 01 (time i calculated) GMT 1970. I was wondering if there is an easy way of just getting the time. I know I can convert it into a String then get the substring of the time, but if I do that i will have to convert it to date again when I am going to use it. Any help would be appreciated I supplied the method below.

public Date curBookingEndTime(){
               //String date= dateTextF.getText();

                    Calendar cal= Calendar.getInstance();
                    DateFormat format= new SimpleDateFormat("hh:mm");
                    java.util.Date dateUtil2 = new java.util.Date();
                    Date calcuDate=null;

                    try {
                        dateUtil2 = format.parse(selected);
                        System.out.println("selected "+ selected);
                    }
                    catch (ParseException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    cal.setTime(dateUtil2);
                    int x= Integer.parseInt(selectGuest);
                    System.out.println("XXXX "+ x);
                    for(int i=1; i<=x;i++){
                        cal.add(cal.MINUTE, 30);
                        if(x==i){
                            System.out.println("cal.getTime "+cal.getTime());
                        calcuDate= cal.getTime();

                        }

        }
                    System.out.println("end time= "+ calcuDate);
                  return calcuDate;
                    }

have answered my own question. sorry!
I dont need time as a Date object.

Love it when that happens. Check out the API for Date. A lot of that class seems to be deprecated, but there are pointers to some classes and methods you might find handy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.