Link to home
Start Free TrialLog in
Avatar of calvinklein1
calvinklein1

asked on

change military time to Standard time

I have a database returning a time to me, but it's in military time.   Like this:
15:00:00
15:15:00
15:30:00
15:45:00
16:00:00
16:15:00

What can I call that will format this time to the regular standard time???  Like this:
3:00 PM
3:15 PM
3:30 PM
4:00 PM
4:15 PM

I was trying to use this:
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
sdf.format(time);

but it only excepts a Date and no time.    Can anyone help me?   Thanks
Avatar of Mick Barry
Mick Barry
Flag of Australia image

SimpleDateFormat standard= new SimpleDateFormat("hh:mm");
SimpleDateFormat military = new SimpleDateFormat("HH:mm");
String regular = standard.format(military.parse(fromdb));

Avatar of maheshexp
maheshexp

Avatar of calvinklein1

ASKER

Thank you object.   but i'm still get an error when trying to parse the object from the database (or in the case the vector that was created from the database).  This is the error:

unhandled exception: java.text.ParseException
and it's for this line code from below:
regular = standard.format(military.parse(y.get(1).toString());

y.get(1)  is an object from the vector that's the way it was put in.   Do I need to cast it to a string or something to make this work???   Here's the method i'm using:

    public ArrayList getTimeSlotTime(){
        ArrayList timeSlotTime = new ArrayList(this.size);
        SimpleDateFormat standard= new SimpleDateFormat("hh:mm");
        SimpleDateFormat military = new SimpleDateFormat("HH:mm");
        String regular;
               
        Vector y;
        for(int i = 0;i < size;i++){
            y = (Vector)slotIdVector.elementAt(i);
            regular = standard.format(military.parse(y.get(1).toString());
            timeSlotTime.add(i,regular);
        }
        return timeSlotTime;
    }
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!!!
Actually, "the regular standard time" as you say is just a queer time format used in the US, while "military time" (24h) is the norm. (Much like the imperial system of measurement).

Come on, catch up =)